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 ()
@@ -24,4 +27,33 @@ function it_creates_a_stream_from_null()
24
27
{
25
28
$ this ->createStream (null )->shouldHaveType ('Psr\Http\Message\StreamInterface ' );
26
29
}
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
+ }
27
59
}
You can’t perform that action at this time.
0 commit comments