@@ -400,6 +400,98 @@ function it_caches_private_responses_when_allowed(
400400 $ this ->handleRequest ($ request , $ next , function () {});
401401 }
402402
403+ function it_does_not_store_responses_of_requests_to_blacklisted_paths (
404+ CacheItemPoolInterface $ pool ,
405+ CacheItemInterface $ item ,
406+ RequestInterface $ request ,
407+ ResponseInterface $ response ,
408+ StreamFactory $ streamFactory ,
409+ StreamInterface $ stream
410+ ) {
411+ $ this ->beConstructedThrough ('clientCache ' , [$ pool , $ streamFactory , [
412+ 'default_ttl ' => 60 ,
413+ 'cache_lifetime ' => 1000 ,
414+ 'blacklisted_paths ' => ['\/foo ' ]
415+ ]]);
416+
417+ $ httpBody = 'body ' ;
418+ $ stream ->__toString ()->willReturn ($ httpBody );
419+ $ stream ->isSeekable ()->willReturn (true );
420+
421+ $ request ->getMethod ()->willReturn ('GET ' );
422+ $ request ->getUri ()->willReturn ('/foo ' );
423+ $ request ->getBody ()->shouldBeCalled ();
424+
425+ $ response ->getStatusCode ()->willReturn (200 );
426+ $ response ->getBody ()->willReturn ($ stream );
427+ $ response ->getHeader ('Cache-Control ' )->willReturn ([])->shouldBeCalled ();
428+
429+ $ pool ->getItem ('231392a16d98e1cf631845c79b7d45f40bab08f3 ' )->shouldBeCalled ()->willReturn ($ item );
430+ $ item ->isHit ()->willReturn (false );
431+
432+ $ item ->set ($ this ->getCacheItemMatcher ([
433+ 'response ' => $ response ->getWrappedObject (),
434+ 'body ' => $ httpBody ,
435+ 'expiresAt ' => 0 ,
436+ 'createdAt ' => 0
437+ ]))->willReturn ($ item )->shouldNotBeCalled ();
438+ $ pool ->save (Argument::any ())->shouldNotBeCalled ();
439+
440+ $ next = function (RequestInterface $ request ) use ($ response ) {
441+ return new FulfilledPromise ($ response ->getWrappedObject ());
442+ };
443+
444+ $ this ->handleRequest ($ request , $ next , function () {});
445+ }
446+
447+ function it_stores_responses_of_requests_not_in_blacklisted_paths (
448+ CacheItemPoolInterface $ pool ,
449+ CacheItemInterface $ item ,
450+ RequestInterface $ request ,
451+ ResponseInterface $ response ,
452+ StreamFactory $ streamFactory ,
453+ StreamInterface $ stream
454+ ) {
455+ $ this ->beConstructedThrough ('clientCache ' , [$ pool , $ streamFactory , [
456+ 'default_ttl ' => 60 ,
457+ 'cache_lifetime ' => 1000 ,
458+ 'blacklisted_paths ' => ['\/foo ' ]
459+ ]]);
460+
461+ $ httpBody = 'body ' ;
462+ $ stream ->__toString ()->willReturn ($ httpBody );
463+ $ stream ->isSeekable ()->willReturn (true );
464+ $ stream ->rewind ()->shouldBeCalled ();
465+
466+ $ request ->getMethod ()->willReturn ('GET ' );
467+ $ request ->getUri ()->willReturn ('/ ' );
468+ $ request ->getBody ()->shouldBeCalled ();
469+
470+ $ response ->getStatusCode ()->willReturn (200 );
471+ $ response ->getBody ()->willReturn ($ stream );
472+ $ response ->getHeader ('Cache-Control ' )->willReturn ([])->shouldBeCalled ();
473+ $ response ->getHeader ('Expires ' )->willReturn ([])->shouldBeCalled ();
474+ $ response ->getHeader ('ETag ' )->willReturn ([])->shouldBeCalled ();
475+
476+ $ pool ->getItem ('d20f64acc6e70b6079845f2fe357732929550ae1 ' )->shouldBeCalled ()->willReturn ($ item );
477+ $ item ->isHit ()->willReturn (false );
478+ $ item ->expiresAfter (1060 )->willReturn ($ item )->shouldBeCalled ();
479+
480+ $ item ->set ($ this ->getCacheItemMatcher ([
481+ 'response ' => $ response ->getWrappedObject (),
482+ 'body ' => $ httpBody ,
483+ 'expiresAt ' => 0 ,
484+ 'createdAt ' => 0 ,
485+ 'etag ' => []
486+ ]))->willReturn ($ item )->shouldBeCalled ();
487+ $ pool ->save (Argument::any ())->shouldBeCalled ();
488+
489+ $ next = function (RequestInterface $ request ) use ($ response ) {
490+ return new FulfilledPromise ($ response ->getWrappedObject ());
491+ };
492+
493+ $ this ->handleRequest ($ request , $ next , function () {});
494+ }
403495
404496 function it_can_be_initialized_with_custom_cache_key_generator (
405497 CacheItemPoolInterface $ pool ,
0 commit comments