@@ -21,6 +21,7 @@ class RelativeStreamTest extends TestCase
2121 public function testToString ()
2222 {
2323 $ decorated = $ this ->prophesize ('Zend\Diactoros\Stream ' );
24+ $ decorated ->tell ()->willReturn (100 );
2425 $ decorated ->seek (100 , SEEK_SET )->shouldBeCalled ();
2526 $ decorated ->getContents ()->shouldBeCalled ()->willReturn ('foobarbaz ' );
2627
@@ -112,6 +113,7 @@ public function testRewind()
112113 public function testWrite ()
113114 {
114115 $ decorated = $ this ->prophesize ('Zend\Diactoros\Stream ' );
116+ $ decorated ->tell ()->willReturn (100 );
115117 $ decorated ->write ("foobaz " )->shouldBeCalled ()->willReturn (6 );
116118 $ stream = new RelativeStream ($ decorated ->reveal (), 100 );
117119 $ ret = $ stream ->write ("foobaz " );
@@ -121,6 +123,7 @@ public function testWrite()
121123 public function testRead ()
122124 {
123125 $ decorated = $ this ->prophesize ('Zend\Diactoros\Stream ' );
126+ $ decorated ->tell ()->willReturn (100 );
124127 $ decorated ->read (3 )->shouldBeCalled ()->willReturn ("foo " );
125128 $ stream = new RelativeStream ($ decorated ->reveal (), 100 );
126129 $ ret = $ stream ->read (3 );
@@ -130,6 +133,7 @@ public function testRead()
130133 public function testGetContents ()
131134 {
132135 $ decorated = $ this ->prophesize ('Zend\Diactoros\Stream ' );
136+ $ decorated ->tell ()->willReturn (100 );
133137 $ decorated ->getContents ()->shouldBeCalled ()->willReturn ("foo " );
134138 $ stream = new RelativeStream ($ decorated ->reveal (), 100 );
135139 $ ret = $ stream ->getContents ();
@@ -144,4 +148,34 @@ public function testGetMetadata()
144148 $ ret = $ stream ->getMetadata ("bar " );
145149 $ this ->assertEquals ("foo " , $ ret );
146150 }
151+
152+ public function testWriteRaisesExceptionWhenPointerIsBehindOffset ()
153+ {
154+ $ this ->setExpectedException ('RuntimeException ' , 'Invalid pointer position ' );
155+ $ decorated = $ this ->prophesize ('Zend\Diactoros\Stream ' );
156+ $ decorated ->tell ()->shouldBeCalled ()->willReturn (0 );
157+ $ decorated ->write ("foobaz " )->shouldNotBeCalled ();
158+ $ stream = new RelativeStream ($ decorated ->reveal (), 100 );
159+ $ stream ->write ("foobaz " );
160+ }
161+
162+ public function testReadRaisesExceptionWhenPointerIsBehindOffset ()
163+ {
164+ $ this ->setExpectedException ('RuntimeException ' , 'Invalid pointer position ' );
165+ $ decorated = $ this ->prophesize ('Zend\Diactoros\Stream ' );
166+ $ decorated ->tell ()->shouldBeCalled ()->willReturn (0 );
167+ $ decorated ->read (3 )->shouldNotBeCalled ();
168+ $ stream = new RelativeStream ($ decorated ->reveal (), 100 );
169+ $ stream ->read (3 );
170+ }
171+
172+ public function testGetContentsRaisesExceptionWhenPointerIsBehindOffset ()
173+ {
174+ $ this ->setExpectedException ('RuntimeException ' , 'Invalid pointer position ' );
175+ $ decorated = $ this ->prophesize ('Zend\Diactoros\Stream ' );
176+ $ decorated ->tell ()->shouldBeCalled ()->willReturn (0 );
177+ $ decorated ->getContents ()->shouldNotBeCalled ();
178+ $ stream = new RelativeStream ($ decorated ->reveal (), 100 );
179+ $ stream ->getContents ();
180+ }
147181}
0 commit comments