/var/www/hkosl.com/littleark/webadmin/libraies/guzzlehttp/psr7/tests/PumpStreamTest.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace GuzzleHttp\Tests\Psr7;

use 
GuzzleHttp\Psr7\LimitStream;
use 
GuzzleHttp\Psr7\PumpStream;
use 
GuzzleHttp\Psr7;

class 
PumpStreamTest extends \PHPUnit_Framework_TestCase
{
    public function 
testHasMetadataAndSize()
    {
        
$p = new PumpStream(function () {}, [
            
'metadata' => ['foo' => 'bar'],
            
'size'     => 100
        
]);

        
$this->assertEquals('bar'$p->getMetadata('foo'));
        
$this->assertEquals(['foo' => 'bar'], $p->getMetadata());
        
$this->assertEquals(100$p->getSize());
    }

    public function 
testCanReadFromCallable()
    {
        
$p Psr7\stream_for(function ($size) {
            return 
'a';
        });
        
$this->assertEquals('a'$p->read(1));
        
$this->assertEquals(1$p->tell());
        
$this->assertEquals('aaaaa'$p->read(5));
        
$this->assertEquals(6$p->tell());
    }

    public function 
testStoresExcessDataInBuffer()
    {
        
$called = [];
        
$p Psr7\stream_for(function ($size) use (&$called) {
            
$called[] = $size;
            return 
'abcdef';
        });
        
$this->assertEquals('a'$p->read(1));
        
$this->assertEquals('b'$p->read(1));
        
$this->assertEquals('cdef'$p->read(4));
        
$this->assertEquals('abcdefabc'$p->read(9));
        
$this->assertEquals([193], $called);
    }

    public function 
testInifiniteStreamWrappedInLimitStream()
    {
        
$p Psr7\stream_for(function () { return 'a'; });
        
$s = new LimitStream($p5);
        
$this->assertEquals('aaaaa', (string) $s);
    }

    public function 
testDescribesCapabilities()
    {
        
$p Psr7\stream_for(function () {});
        
$this->assertTrue($p->isReadable());
        
$this->assertFalse($p->isSeekable());
        
$this->assertFalse($p->isWritable());
        
$this->assertNull($p->getSize());
        
$this->assertEquals(''$p->getContents());
        
$this->assertEquals('', (string) $p);
        
$p->close();
        
$this->assertEquals(''$p->read(10));
        
$this->assertTrue($p->eof());

        try {
            
$this->assertFalse($p->write('aa'));
            
$this->fail();
        } catch (\
RuntimeException $e) {}
    }
}