PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.4.2
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.4.2
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
stockpack / vendor / guzzlehttp / psr7 / tests / FnStreamTest.php

FnStreamTest.php in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 2.4.2, at vendor/guzzlehttp/psr7/tests/FnStreamTest.php

100 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace GuzzleHttp\Tests\Psr7;
3
4 use GuzzleHttp\Psr7;
5 use GuzzleHttp\Psr7\FnStream;
6
7 /**
8 * @covers GuzzleHttp\Psr7\FnStream
9 */
10 class FnStreamTest extends BaseTest
11 {
12 /**
13 * @expectedException \BadMethodCallException
14 * @expectedExceptionMessage seek() is not implemented in the FnStream
15 */
16 public function testThrowsWhenNotImplemented()
17 {
18 (new FnStream([]))->seek(1);
19 }
20
21 public function testProxiesToFunction()
22 {
23 $s = new FnStream([
24 'read' => function ($len) {
25 $this->assertEquals(3, $len);
26 return 'foo';
27 }
28 ]);
29
30 $this->assertEquals('foo', $s->read(3));
31 }
32
33 public function testCanCloseOnDestruct()
34 {
35 $called = false;
36 $s = new FnStream([
37 'close' => function () use (&$called) {
38 $called = true;
39 }
40 ]);
41 unset($s);
42 $this->assertTrue($called);
43 }
44
45 public function testDoesNotRequireClose()
46 {
47 $s = new FnStream([]);
48 unset($s);
49 $this->assertTrue(true); // strict mode requires an assertion
50 }
51
52 public function testDecoratesStream()
53 {
54 $a = Psr7\stream_for('foo');
55 $b = FnStream::decorate($a, []);
56 $this->assertEquals(3, $b->getSize());
57 $this->assertEquals($b->isWritable(), true);
58 $this->assertEquals($b->isReadable(), true);
59 $this->assertEquals($b->isSeekable(), true);
60 $this->assertEquals($b->read(3), 'foo');
61 $this->assertEquals($b->tell(), 3);
62 $this->assertEquals($a->tell(), 3);
63 $this->assertSame('', $a->read(1));
64 $this->assertEquals($b->eof(), true);
65 $this->assertEquals($a->eof(), true);
66 $b->seek(0);
67 $this->assertEquals('foo', (string) $b);
68 $b->seek(0);
69 $this->assertEquals('foo', $b->getContents());
70 $this->assertEquals($a->getMetadata(), $b->getMetadata());
71 $b->seek(0, SEEK_END);
72 $b->write('bar');
73 $this->assertEquals('foobar', (string) $b);
74 $this->assertInternalType('resource', $b->detach());
75 $b->close();
76 }
77
78 public function testDecoratesWithCustomizations()
79 {
80 $called = false;
81 $a = Psr7\stream_for('foo');
82 $b = FnStream::decorate($a, [
83 'read' => function ($len) use (&$called, $a) {
84 $called = true;
85 return $a->read($len);
86 }
87 ]);
88 $this->assertEquals('foo', $b->read(3));
89 $this->assertTrue($called);
90 }
91
92 public function testDoNotAllowUnserialization()
93 {
94 $a = new FnStream([]);
95 $b = serialize($a);
96 $this->expectException('\LogicException', 'FnStream should never be unserialized');
97 unserialize($b);
98 }
99 }
100