|
19 | 19 | use Symfony\Component\DependencyInjection\Container; |
20 | 20 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
21 | 21 | use Symfony\Component\DependencyInjection\ContainerInterface; |
22 | | -use Symfony\Component\DependencyInjection\Reference; |
23 | 22 | use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
24 | 23 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
| 24 | +use Symfony\Component\DependencyInjection\Reference; |
25 | 25 | use Symfony\Component\Filesystem\Exception\IOException; |
26 | 26 | use Symfony\Component\Filesystem\Filesystem; |
27 | 27 | use Symfony\Component\HttpFoundation\Request; |
@@ -633,6 +633,29 @@ public function testServicesAreNotResetBetweenHttpCacheFragments() |
633 | 633 | $this->assertSame(1, ResettableService::$counter); |
634 | 634 | } |
635 | 635 |
|
| 636 | + public function testHttpCacheHandlesRequestsAfterKernelBoot() |
| 637 | + { |
| 638 | + $kernel = new CustomProjectDirKernel(static function (ContainerBuilder $container) { |
| 639 | + $container->register('http_cache', RecordingHttpCache::class) |
| 640 | + ->setPublic(true); |
| 641 | + }, new ThrowingHttpKernel(), 'http_cache_worker'); |
| 642 | + |
| 643 | + $kernel->boot(); |
| 644 | + |
| 645 | + $firstResponse = $kernel->handle(Request::create('/worker-first')); |
| 646 | + $secondResponse = $kernel->handle(Request::create('/worker-second')); |
| 647 | + |
| 648 | + /** @var RecordingHttpCache $httpCache */ |
| 649 | + $httpCache = $kernel->getContainer()->get('http_cache'); |
| 650 | + |
| 651 | + $this->assertSame([ |
| 652 | + ['/worker-first', HttpKernelInterface::MAIN_REQUEST], |
| 653 | + ['/worker-second', HttpKernelInterface::MAIN_REQUEST], |
| 654 | + ], $httpCache->handledPaths); |
| 655 | + $this->assertSame('cached: /worker-first', $firstResponse->getContent()); |
| 656 | + $this->assertSame('cached: /worker-second', $secondResponse->getContent()); |
| 657 | + } |
| 658 | + |
636 | 659 | /** |
637 | 660 | * @group time-sensitive |
638 | 661 | */ |
@@ -882,3 +905,23 @@ public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $c |
882 | 905 | return new Response(implode('', array_map(static fn (Response $response) => $response->getContent(), $responses))); |
883 | 906 | } |
884 | 907 | } |
| 908 | + |
| 909 | +class RecordingHttpCache implements HttpKernelInterface |
| 910 | +{ |
| 911 | + public array $handledPaths = []; |
| 912 | + |
| 913 | + public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response |
| 914 | + { |
| 915 | + $this->handledPaths[] = [$request->getPathInfo(), $type]; |
| 916 | + |
| 917 | + return new Response('cached: '.$request->getPathInfo()); |
| 918 | + } |
| 919 | +} |
| 920 | + |
| 921 | +class ThrowingHttpKernel implements HttpKernelInterface |
| 922 | +{ |
| 923 | + public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response |
| 924 | + { |
| 925 | + throw new \LogicException('The worker HTTP kernel should not be reached when the http_cache service handles the request.'); |
| 926 | + } |
| 927 | +} |
0 commit comments