From 4350695b87be9e5ba06d353a36bd011be8d836bf Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Mon, 12 May 2025 11:18:01 +0200 Subject: [PATCH 1/4] [Tests] Add coverage for cache control expression language --- .../FOSHttpCacheExtensionTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php b/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php index 1e54d628..ab181619 100644 --- a/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php +++ b/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php @@ -489,6 +489,24 @@ public function testConfigLoadCacheControlExpression(): void $this->assertListenerHasRule($container, 'fos_http_cache.event_listener.cache_control'); } + public function testConfigLoadCacheControlExpressionWithOverriddenExpressionLanguage(): void + { + $config = $this->getCacheControlExpressionFullConfig(); + + $container = $this->createContainer(); + $this->extension->load([$config], $container); + + $id = 'fos_http_cache.cache_control.expression.'.md5('foobar'); + $this->assertTrue($container->hasDefinition($id), 'expression child definition not created as expected'); + $this->assertEquals( + [ + 'foobar', + new Reference('app.expression_language'), + ], + $container->getDefinition($id)->getArguments() + ); + } + /** * Check if comma separated strings are parsed as expected. */ @@ -813,6 +831,28 @@ private function getBaseConfig(): array ]; } + /** + * @return array + */ + private function getCacheControlExpressionFullConfig(): array + { + return [ + 'cache_control' => [ + 'rules' => [ + [ + 'match' => [ + 'match_response' => 'foobar', + 'expression_language' => 'app.expression_language', + ], + 'headers' => [ + 'cache_control' => ['public' => true], + ], + ], + ], + ], + ]; + } + /** * @param array $methods List of methods for the matcher. Empty array to not check. * From a45281065565be31659debdb16af85b6d856df36 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Mon, 12 May 2025 11:18:56 +0200 Subject: [PATCH 2/4] [Tests] Add coverage for expression config container compilation --- .../FOSHttpCacheExtensionTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php b/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php index ab181619..174387a9 100644 --- a/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php +++ b/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php @@ -26,6 +26,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\Routing\Router; @@ -507,6 +508,20 @@ public function testConfigLoadCacheControlExpressionWithOverriddenExpressionLang ); } + public function testContainerCompilesWithCacheControlExpressionConfig(): void + { + $config = $this->getCacheControlExpressionFullConfig(); + + $container = $this->createContainer(); + $this->extension->load([$config], $container); + + $container->addDefinitions(['app.expression_language' => new Definition(ExpressionLanguage::class)]); + + $container->compile(); + + $this->expectNotToPerformAssertions(); + } + /** * Check if comma separated strings are parsed as expected. */ From 30d0afca8487d7bdab978bccb40287095c8a2c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Thu, 8 May 2025 09:25:04 +0200 Subject: [PATCH 3/4] Fix configuring cache control expression for Symfony Container --- src/DependencyInjection/FOSHttpCacheExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/FOSHttpCacheExtension.php b/src/DependencyInjection/FOSHttpCacheExtension.php index d7236752..aab6b181 100644 --- a/src/DependencyInjection/FOSHttpCacheExtension.php +++ b/src/DependencyInjection/FOSHttpCacheExtension.php @@ -259,7 +259,7 @@ private function parseResponseMatcher(ContainerBuilder $container, array $config $id = 'fos_http_cache.cache_control.expression.'.md5($config['match_response']); if (!$container->hasDefinition($id)) { $childDefinition = (new ChildDefinition('fos_http_cache.response_matcher.cache_control.expression')) - ->replaceArgument(0, $config['match_response']) + ->setArgument(0, $config['match_response']) ; if (!empty($config['match_response_expression_service'])) { $childDefinition->replaceArgument(1, new Reference($config['match_response_expression_service'])); From 58c6948da757c0f5334c3093e31f61b84a6d0a34 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Mon, 12 May 2025 11:33:13 +0200 Subject: [PATCH 4/4] Fix configuring cache control expression language for Symfony Container --- src/DependencyInjection/FOSHttpCacheExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DependencyInjection/FOSHttpCacheExtension.php b/src/DependencyInjection/FOSHttpCacheExtension.php index aab6b181..9d0c0f44 100644 --- a/src/DependencyInjection/FOSHttpCacheExtension.php +++ b/src/DependencyInjection/FOSHttpCacheExtension.php @@ -261,8 +261,8 @@ private function parseResponseMatcher(ContainerBuilder $container, array $config $childDefinition = (new ChildDefinition('fos_http_cache.response_matcher.cache_control.expression')) ->setArgument(0, $config['match_response']) ; - if (!empty($config['match_response_expression_service'])) { - $childDefinition->replaceArgument(1, new Reference($config['match_response_expression_service'])); + if (!empty($config['expression_language'])) { + $childDefinition->setArgument(1, new Reference($config['expression_language'])); } $container ->setDefinition($id, $childDefinition)