1<?php
2namespace GuzzleHttp\Tests\Stream;
3
4use GuzzleHttp\Stream\Stream;
5use GuzzleHttp\Stream\NoSeekStream;
6use PHPUnit\Framework\TestCase;
7
8/**
9 * @covers GuzzleHttp\Stream\NoSeekStream
10 * @covers GuzzleHttp\Stream\StreamDecoratorTrait
11 */
12class NoSeekStreamTest extends TestCase
13{
14    public function testCannotSeek()
15    {
16        $s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
17            ->setMethods(['isSeekable', 'seek'])
18            ->getMockForAbstractClass();
19        $s->expects($this->never())->method('seek');
20        $s->expects($this->never())->method('isSeekable');
21        $wrapped = new NoSeekStream($s);
22        $this->assertFalse($wrapped->isSeekable());
23        $this->assertFalse($wrapped->seek(2));
24    }
25
26    public function testHandlesClose()
27    {
28        $s = Stream::factory('foo');
29        $wrapped = new NoSeekStream($s);
30        $wrapped->close();
31        $this->assertFalse($wrapped->write('foo'));
32    }
33
34    public function testCanAttach()
35    {
36        $s1 = Stream::factory('foo');
37        $s2 = Stream::factory('bar');
38        $wrapped = new NoSeekStream($s1);
39        $wrapped->attach($s2->detach());
40        $this->assertEquals('bar', (string) $wrapped);
41    }
42}
43