File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace spec \Http \Message \StreamFactory ;
4
4
5
+ use GuzzleHttp \Psr7 \Stream ;
6
+ use Psr \Http \Message \StreamInterface ;
7
+
5
8
trait StreamFactoryBehavior
6
9
{
7
10
function it_is_a_stream_factory ()
@@ -32,4 +35,33 @@ function it_creates_a_stream_from_non_seekable_resource()
32
35
$ this ->createStream ($ resource )
33
36
->shouldHaveType ('Psr\Http\Message\StreamInterface ' );
34
37
}
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
+ }
35
67
}
You can’t perform that action at this time.
0 commit comments