Skip to content

Commit 6d013c3

Browse files
committed
Test if we rewind existing stream/resource
1 parent a89f53c commit 6d013c3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

spec/StreamFactory/StreamFactoryBehavior.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace spec\Http\Message\StreamFactory;
44

5+
use GuzzleHttp\Psr7\Stream;
6+
use Psr\Http\Message\StreamInterface;
7+
58
trait StreamFactoryBehavior
69
{
710
function it_is_a_stream_factory()
@@ -32,4 +35,33 @@ function it_creates_a_stream_from_non_seekable_resource()
3235
$this->createStream($resource)
3336
->shouldHaveType('Psr\Http\Message\StreamInterface');
3437
}
38+
39+
function it_rewinds_existing_stream()
40+
{
41+
$stream = new Stream(fopen('php://memory', 'rw'));
42+
$stream->write('abcdef');
43+
$stream->read(3);
44+
45+
$this->createStream($stream)
46+
->shouldHaveContent('abcdef');
47+
}
48+
49+
function it_rewinds_existing_resource()
50+
{
51+
$resource = fopen('php://memory', 'rw');
52+
fwrite($resource, 'abcdef');
53+
fread($resource, 3);
54+
55+
$this->createStream($resource)
56+
->shouldHaveContent('abcdef');
57+
}
58+
59+
public function getMatchers()
60+
{
61+
return [
62+
'haveContent' => function (StreamInterface $subject, $key) {
63+
return $subject->getContents() === $key;
64+
},
65+
];
66+
}
3567
}

0 commit comments

Comments
 (0)