2
namespace GuzzleHttp\Tests\Stream;
4
use GuzzleHttp\Stream\Stream;
5
use GuzzleHttp\Stream\FnStream;
8
* @covers GuzzleHttp\Stream\FnStream
10
class FnStreamTest extends \PHPUnit_Framework_TestCase
13
* @expectedException \BadMethodCallException
14
* @expectedExceptionMessage seek() is not implemented in the FnStream
16
public function testThrowsWhenNotImplemented()
18
(new FnStream([]))->seek(1);
21
public function testProxiesToFunction()
24
'read' => function ($len) {
25
$this->assertEquals(3, $len);
30
$this->assertEquals('foo', $s->read(3));
33
public function testCanCloseOnDestruct()
37
'close' => function () use (&$called) {
42
$this->assertTrue($called);
45
public function testDoesNotRequireClose()
47
$s = new FnStream([]);
51
public function testDecoratesStream()
53
$a = Stream::factory('foo');
54
$b = FnStream::decorate($a, []);
55
$this->assertEquals(3, $b->getSize());
56
$this->assertEquals($b->isWritable(), true);
57
$this->assertEquals($b->isReadable(), true);
58
$this->assertEquals($b->isSeekable(), true);
59
$this->assertEquals($b->read(3), 'foo');
60
$this->assertEquals($b->tell(), 3);
61
$this->assertEquals($a->tell(), 3);
62
$this->assertEquals($b->eof(), true);
63
$this->assertEquals($a->eof(), true);
65
$this->assertEquals('foo', (string) $b);
67
$this->assertEquals('foo', $b->getContents());
68
$this->assertEquals($a->getMetadata(), $b->getMetadata());
69
$b->seek(0, SEEK_END);
71
$this->assertEquals('foobar', (string) $b);
73
$this->assertInternalType('resource', $b->detach());
77
public function testDecoratesWithCustomizations()
80
$a = Stream::factory('foo');
81
$b = FnStream::decorate($a, [
82
'read' => function ($len) use (&$called, $a) {
84
return $a->read($len);
87
$this->assertEquals('foo', $b->read(3));
88
$this->assertTrue($called);