Skip to content

Commit d7a8eaf

Browse files
committed
Test if we rewind existing stream/resource
1 parent 016359f commit d7a8eaf

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()
@@ -24,4 +27,33 @@ function it_creates_a_stream_from_null()
2427
{
2528
$this->createStream(null)->shouldHaveType('Psr\Http\Message\StreamInterface');
2629
}
30+
31+
function it_rewinds_existing_stream()
32+
{
33+
$stream = new Stream(fopen('php://memory', 'rw'));
34+
$stream->write('abcdef');
35+
$stream->read(3);
36+
37+
$this->createStream($stream)
38+
->shouldHaveContent('abcdef');
39+
}
40+
41+
function it_rewinds_existing_resource()
42+
{
43+
$resource = fopen('php://memory', 'rw');
44+
fwrite($resource, 'abcdef');
45+
fread($resource, 3);
46+
47+
$this->createStream($resource)
48+
->shouldHaveContent('abcdef');
49+
}
50+
51+
public function getMatchers()
52+
{
53+
return [
54+
'haveContent' => function (StreamInterface $subject, $key) {
55+
return $subject->getContents() === $key;
56+
},
57+
];
58+
}
2759
}

0 commit comments

Comments
 (0)