1313use Psr \Http \Message \ResponseInterface ;
1414use Psr \Http \Message \StreamInterface ;
1515use Psr \Http \Message \UriInterface ;
16+ use Http \Client \Common \Plugin \CachePlugin ;
17+ use Http \Client \Common \Plugin ;
1618
1719class CachePluginSpec extends ObjectBehavior
1820{
@@ -26,12 +28,12 @@ function let(CacheItemPoolInterface $pool, StreamFactory $streamFactory)
2628
2729 function it_is_initializable (CacheItemPoolInterface $ pool )
2830 {
29- $ this ->shouldHaveType (' Http\Client\Common\Plugin\ CachePlugin' );
31+ $ this ->shouldHaveType (CachePlugin::class );
3032 }
3133
3234 function it_is_a_plugin ()
3335 {
34- $ this ->shouldImplement (' Http\Client\Common\ Plugin' );
36+ $ this ->shouldImplement (Plugin::class );
3537 }
3638
3739 function it_caches_responses (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response , StreamInterface $ stream )
@@ -44,7 +46,7 @@ function it_caches_responses(CacheItemPoolInterface $pool, CacheItemInterface $i
4446 $ request ->getMethod ()->willReturn ('GET ' );
4547 $ request ->getUri ()->willReturn ($ uri );
4648 $ uri ->__toString ()->willReturn ('https://example.com/ ' );
47- $ request ->getBody ()->shouldBeCalled ();
49+ $ request ->getBody ()->shouldBeCalled ()-> willReturn ( $ stream ) ;
4850
4951 $ response ->getStatusCode ()->willReturn (200 );
5052 $ response ->getBody ()->willReturn ($ stream );
@@ -72,12 +74,13 @@ function it_caches_responses(CacheItemPoolInterface $pool, CacheItemInterface $i
7274 $ this ->handleRequest ($ request , $ next , function () {});
7375 }
7476
75- function it_doesnt_store_failed_responses (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response )
77+ function it_doesnt_store_failed_responses (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , StreamInterface $ requestBody , ResponseInterface $ response )
7678 {
7779 $ request ->getMethod ()->willReturn ('GET ' );
7880 $ request ->getUri ()->willReturn ($ uri );
7981 $ uri ->__toString ()->willReturn ('https://example.com/ ' );
80- $ request ->getBody ()->shouldBeCalled ();
82+ $ request ->getBody ()->shouldBeCalled ()->willReturn ($ requestBody );
83+ $ requestBody ->__toString ()->shouldBeCalled ()->willReturn ('body ' );
8184
8285 $ response ->getStatusCode ()->willReturn (400 );
8386 $ response ->getHeader ('Cache-Control ' )->willReturn ([]);
@@ -187,7 +190,7 @@ function it_calculate_age_from_response(CacheItemPoolInterface $pool, CacheItemI
187190 $ request ->getMethod ()->willReturn ('GET ' );
188191 $ request ->getUri ()->willReturn ($ uri );
189192 $ uri ->__toString ()->willReturn ('https://example.com/ ' );
190- $ request ->getBody ()->shouldBeCalled ();
193+ $ request ->getBody ()->shouldBeCalled ()-> willReturn ( $ stream ) ;
191194
192195 $ response ->getStatusCode ()->willReturn (200 );
193196 $ response ->getBody ()->willReturn ($ stream );
@@ -223,7 +226,7 @@ function it_saves_etag(CacheItemPoolInterface $pool, CacheItemInterface $item, R
223226 $ stream ->__toString ()->willReturn ($ httpBody );
224227 $ stream ->isSeekable ()->willReturn (true );
225228 $ stream ->rewind ()->shouldBeCalled ();
226- $ request ->getBody ()->shouldBeCalled ();
229+ $ request ->getBody ()->shouldBeCalled ()-> willReturn ( $ stream ) ;
227230
228231 $ request ->getMethod ()->willReturn ('GET ' );
229232 $ request ->getUri ()->willReturn ($ uri );
@@ -261,7 +264,8 @@ function it_adds_etag_and_modfied_since_to_request(CacheItemPoolInterface $pool,
261264 $ request ->getMethod ()->willReturn ('GET ' );
262265 $ request ->getUri ()->willReturn ($ uri );
263266 $ uri ->__toString ()->willReturn ('https://example.com/ ' );
264- $ request ->getBody ()->shouldBeCalled ();
267+ $ request ->getBody ()->shouldBeCalled ()->willReturn ($ stream );
268+ $ stream ->__toString ()->shouldBeCalled ()->willReturn ('' );
265269
266270 $ request ->withHeader ('If-Modified-Since ' , 'Thursday, 01-Jan-70 01:18:31 GMT ' )->shouldBeCalled ()->willReturn ($ request );
267271 $ request ->withHeader ('If-None-Match ' , 'foo_etag ' )->shouldBeCalled ()->willReturn ($ request );
@@ -285,14 +289,15 @@ function it_adds_etag_and_modfied_since_to_request(CacheItemPoolInterface $pool,
285289 $ this ->handleRequest ($ request , $ next , function () {});
286290 }
287291
288- function it_servces_a_cached_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response , StreamInterface $ stream , StreamFactory $ streamFactory )
292+ function it_serves_a_cached_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri, StreamInterface $ requestBody , ResponseInterface $ response , StreamInterface $ stream , StreamFactory $ streamFactory )
289293 {
290294 $ httpBody = 'body ' ;
291295
292296 $ request ->getMethod ()->willReturn ('GET ' );
293297 $ request ->getUri ()->willReturn ($ uri );
294298 $ uri ->__toString ()->willReturn ('https://example.com/ ' );
295- $ request ->getBody ()->shouldBeCalled ();
299+ $ request ->getBody ()->shouldBeCalled ()->willReturn ($ requestBody );
300+ $ requestBody ->__toString ()->shouldBeCalled ()->willReturn ('' );
296301
297302 $ pool ->getItem (Argument::any ())->shouldBeCalled ()->willReturn ($ item );
298303 $ item ->isHit ()->willReturn (true );
@@ -315,14 +320,15 @@ function it_servces_a_cached_response(CacheItemPoolInterface $pool, CacheItemInt
315320 $ this ->handleRequest ($ request , $ next , function () {});
316321 }
317322
318- function it_serves_and_resaved_expired_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , ResponseInterface $ response , StreamInterface $ stream , StreamFactory $ streamFactory )
323+ function it_serves_and_resaved_expired_response (CacheItemPoolInterface $ pool , CacheItemInterface $ item , RequestInterface $ request , UriInterface $ uri , StreamInterface $ requestStream , ResponseInterface $ response , StreamInterface $ stream , StreamFactory $ streamFactory )
319324 {
320325 $ httpBody = 'body ' ;
321326
322327 $ request ->getMethod ()->willReturn ('GET ' );
323328 $ request ->getUri ()->willReturn ($ uri );
324329 $ uri ->__toString ()->willReturn ('https://example.com/ ' );
325- $ request ->getBody ()->shouldBeCalled ();
330+ $ request ->getBody ()->shouldBeCalled ()->willReturn ($ requestStream );
331+ $ requestStream ->__toString ()->willReturn ('' );
326332
327333 $ request ->withHeader (Argument::any (), Argument::any ())->willReturn ($ request );
328334 $ request ->withHeader (Argument::any (), Argument::any ())->willReturn ($ request );
@@ -385,7 +391,7 @@ function it_caches_private_responses_when_allowed(
385391 $ request ->getMethod ()->willReturn ('GET ' );
386392 $ request ->getUri ()->willReturn ($ uri );
387393 $ uri ->__toString ()->willReturn ('https://example.com/ ' );
388- $ request ->getBody ()->shouldBeCalled ();
394+ $ request ->getBody ()->shouldBeCalled ()-> willReturn ( $ stream ) ;
389395
390396 $ response ->getStatusCode ()->willReturn (200 );
391397 $ response ->getBody ()->willReturn ($ stream );
@@ -435,7 +441,7 @@ function it_does_not_store_responses_of_requests_to_blacklisted_paths(
435441 $ request ->getMethod ()->willReturn ('GET ' );
436442 $ request ->getUri ()->willReturn ($ uri );
437443 $ uri ->__toString ()->willReturn ('https://example.com/foo ' );
438- $ request ->getBody ()->shouldBeCalled ();
444+ $ request ->getBody ()->shouldBeCalled ()-> willReturn ( $ stream ) ;
439445
440446 $ response ->getStatusCode ()->willReturn (200 );
441447 $ response ->getBody ()->willReturn ($ stream );
@@ -482,7 +488,7 @@ function it_stores_responses_of_requests_not_in_blacklisted_paths(
482488 $ request ->getMethod ()->willReturn ('GET ' );
483489 $ request ->getUri ()->willReturn ($ uri );
484490 $ uri ->__toString ()->willReturn ('https://example.com/ ' );
485- $ request ->getBody ()->shouldBeCalled ();
491+ $ request ->getBody ()->shouldBeCalled ()-> willReturn ( $ stream ) ;
486492
487493 $ response ->getStatusCode ()->willReturn (200 );
488494 $ response ->getBody ()->willReturn ($ stream );
0 commit comments