diff --git a/src/DependencyInjection/FOSHttpCacheExtension.php b/src/DependencyInjection/FOSHttpCacheExtension.php index d7236752..9d0c0f44 100644 --- a/src/DependencyInjection/FOSHttpCacheExtension.php +++ b/src/DependencyInjection/FOSHttpCacheExtension.php @@ -259,10 +259,10 @@ 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'])); + if (!empty($config['expression_language'])) { + $childDefinition->setArgument(1, new Reference($config['expression_language'])); } $container ->setDefinition($id, $childDefinition) diff --git a/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php b/tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php index 1e54d628..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; @@ -489,6 +490,38 @@ 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() + ); + } + + 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. */ @@ -813,6 +846,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. *