PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.5.7
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.5.7
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 / PumpStreamTest.php

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

73 lines 2.1 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\LimitStream;
5 use GuzzleHttp\Psr7\PumpStream;
6 use GuzzleHttp\Psr7;
7
8 class PumpStreamTest extends BaseTest
9 {
10 public function testHasMetadataAndSize()
11 {
12 $p = new PumpStream(function () {}, [
13 'metadata' => ['foo' => 'bar'],
14 'size' => 100
15 ]);
16
17 $this->assertEquals('bar', $p->getMetadata('foo'));
18 $this->assertEquals(['foo' => 'bar'], $p->getMetadata());
19 $this->assertEquals(100, $p->getSize());
20 }
21
22 public function testCanReadFromCallable()
23 {
24 $p = Psr7\stream_for(function ($size) {
25 return 'a';
26 });
27 $this->assertEquals('a', $p->read(1));
28 $this->assertEquals(1, $p->tell());
29 $this->assertEquals('aaaaa', $p->read(5));
30 $this->assertEquals(6, $p->tell());
31 }
32
33 public function testStoresExcessDataInBuffer()
34 {
35 $called = [];
36 $p = Psr7\stream_for(function ($size) use (&$called) {
37 $called[] = $size;
38 return 'abcdef';
39 });
40 $this->assertEquals('a', $p->read(1));
41 $this->assertEquals('b', $p->read(1));
42 $this->assertEquals('cdef', $p->read(4));
43 $this->assertEquals('abcdefabc', $p->read(9));
44 $this->assertEquals([1, 9, 3], $called);
45 }
46
47 public function testInifiniteStreamWrappedInLimitStream()
48 {
49 $p = Psr7\stream_for(function () { return 'a'; });
50 $s = new LimitStream($p, 5);
51 $this->assertEquals('aaaaa', (string) $s);
52 }
53
54 public function testDescribesCapabilities()
55 {
56 $p = Psr7\stream_for(function () {});
57 $this->assertTrue($p->isReadable());
58 $this->assertFalse($p->isSeekable());
59 $this->assertFalse($p->isWritable());
60 $this->assertNull($p->getSize());
61 $this->assertEquals('', $p->getContents());
62 $this->assertEquals('', (string) $p);
63 $p->close();
64 $this->assertEquals('', $p->read(10));
65 $this->assertTrue($p->eof());
66
67 try {
68 $this->assertFalse($p->write('aa'));
69 $this->fail();
70 } catch (\RuntimeException $e) {}
71 }
72 }
73