@@ -527,6 +527,29 @@ public function testServicesAreNotResetBetweenHttpCacheFragments()
527527 $ this ->assertSame (1 , ResettableService::$ counter );
528528 }
529529
530+ public function testHttpCacheHandlesRequestsAfterKernelBoot ()
531+ {
532+ $ kernel = new CustomProjectDirKernel (static function (ContainerBuilder $ container ) {
533+ $ container ->register ('http_cache ' , RecordingHttpCache::class)
534+ ->setPublic (true );
535+ }, new ThrowingHttpKernel (), 'http_cache_worker ' );
536+
537+ $ kernel ->boot ();
538+
539+ $ firstResponse = $ kernel ->handle (Request::create ('/worker-first ' ));
540+ $ secondResponse = $ kernel ->handle (Request::create ('/worker-second ' ));
541+
542+ /** @var RecordingHttpCache $httpCache */
543+ $ httpCache = $ kernel ->getContainer ()->get ('http_cache ' );
544+
545+ $ this ->assertSame ([
546+ ['/worker-first ' , HttpKernelInterface::MAIN_REQUEST ],
547+ ['/worker-second ' , HttpKernelInterface::MAIN_REQUEST ],
548+ ], $ httpCache ->handledPaths );
549+ $ this ->assertSame ('cached: /worker-first ' , $ firstResponse ->getContent ());
550+ $ this ->assertSame ('cached: /worker-second ' , $ secondResponse ->getContent ());
551+ }
552+
530553 #[Group('time-sensitive ' )]
531554 public function testKernelStartTimeIsResetWhileBootingAlreadyBootedKernel ()
532555 {
@@ -759,6 +782,62 @@ public function process(ContainerBuilder $container): void
759782 }
760783}
761784
785+ class FragmentHandlingKernel implements HttpKernelInterface
786+ {
787+ public array $ handledPaths = [];
788+ public array $ resetCounters = [];
789+
790+ public function handle (Request $ request , int $ type = self ::MAIN_REQUEST , bool $ catch = true ): Response
791+ {
792+ $ this ->handledPaths [] = [$ request ->getPathInfo (), $ type ];
793+ $ this ->resetCounters [] = ResettableService::$ counter ;
794+
795+ return new Response ($ request ->getPathInfo ());
796+ }
797+ }
798+
799+ class FragmentRenderingHttpCache implements HttpKernelInterface
800+ {
801+ public function __construct (
802+ private KernelInterface $ kernel ,
803+ private string $ trackedServiceId = 'one ' ,
804+ ) {
805+ }
806+
807+ public function handle (Request $ request , int $ type = self ::MAIN_REQUEST , bool $ catch = true ): Response
808+ {
809+ $ this ->kernel ->boot ();
810+ $ this ->kernel ->getContainer ()->get ($ this ->trackedServiceId );
811+
812+ $ responses = [];
813+ foreach (['/first-fragment ' , '/second-fragment ' ] as $ path ) {
814+ $ responses [] = $ this ->kernel ->handle (Request::create ($ path ), self ::MAIN_REQUEST , $ catch );
815+ }
816+
817+ return new Response (implode ('' , array_map (static fn (Response $ response ) => $ response ->getContent (), $ responses )));
818+ }
819+ }
820+
821+ class RecordingHttpCache implements HttpKernelInterface
822+ {
823+ public array $ handledPaths = [];
824+
825+ public function handle (Request $ request , int $ type = self ::MAIN_REQUEST , bool $ catch = true ): Response
826+ {
827+ $ this ->handledPaths [] = [$ request ->getPathInfo (), $ type ];
828+
829+ return new Response ('cached: ' .$ request ->getPathInfo ());
830+ }
831+ }
832+
833+ class ThrowingHttpKernel implements HttpKernelInterface
834+ {
835+ public function handle (Request $ request , int $ type = self ::MAIN_REQUEST , bool $ catch = true ): Response
836+ {
837+ throw new \LogicException ('The worker HTTP kernel should not be reached when the http_cache service handles the request. ' );
838+ }
839+ }
840+
762841class KernelForTest extends Kernel
763842{
764843 public function __construct (string $ environment , bool $ debug , private readonly bool $ fakeContainer = true )
@@ -806,39 +885,3 @@ public function doLoadClassCache(): void
806885 {
807886 }
808887}
809-
810- class FragmentHandlingKernel implements HttpKernelInterface
811- {
812- public array $ handledPaths = [];
813- public array $ resetCounters = [];
814-
815- public function handle (Request $ request , int $ type = self ::MAIN_REQUEST , bool $ catch = true ): Response
816- {
817- $ this ->handledPaths [] = [$ request ->getPathInfo (), $ type ];
818- $ this ->resetCounters [] = ResettableService::$ counter ;
819-
820- return new Response ($ request ->getPathInfo ());
821- }
822- }
823-
824- class FragmentRenderingHttpCache implements HttpKernelInterface
825- {
826- public function __construct (
827- private KernelInterface $ kernel ,
828- private string $ trackedServiceId = 'one ' ,
829- ) {
830- }
831-
832- public function handle (Request $ request , int $ type = self ::MAIN_REQUEST , bool $ catch = true ): Response
833- {
834- $ this ->kernel ->boot ();
835- $ this ->kernel ->getContainer ()->get ($ this ->trackedServiceId );
836-
837- $ responses = [];
838- foreach (['/first-fragment ' , '/second-fragment ' ] as $ path ) {
839- $ responses [] = $ this ->kernel ->handle (Request::create ($ path ), self ::MAIN_REQUEST , $ catch );
840- }
841-
842- return new Response (implode ('' , array_map (static fn (Response $ response ) => $ response ->getContent (), $ responses )));
843- }
844- }
0 commit comments