|
26 | 26 | use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
27 | 27 | use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
|
28 | 28 | use Symfony\Component\DependencyInjection\Reference;
|
| 29 | +use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
29 | 30 | use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
|
30 | 31 | use Symfony\Component\Routing\Router;
|
31 | 32 |
|
@@ -489,6 +490,38 @@ public function testConfigLoadCacheControlExpression(): void
|
489 | 490 | $this->assertListenerHasRule($container, 'fos_http_cache.event_listener.cache_control');
|
490 | 491 | }
|
491 | 492 |
|
| 493 | + public function testConfigLoadCacheControlExpressionWithOverriddenExpressionLanguage(): void |
| 494 | + { |
| 495 | + $config = $this->getCacheControlExpressionFullConfig(); |
| 496 | + |
| 497 | + $container = $this->createContainer(); |
| 498 | + $this->extension->load([$config], $container); |
| 499 | + |
| 500 | + $id = 'fos_http_cache.cache_control.expression.'.md5('foobar'); |
| 501 | + $this->assertTrue($container->hasDefinition($id), 'expression child definition not created as expected'); |
| 502 | + $this->assertEquals( |
| 503 | + [ |
| 504 | + 'foobar', |
| 505 | + new Reference('app.expression_language'), |
| 506 | + ], |
| 507 | + $container->getDefinition($id)->getArguments() |
| 508 | + ); |
| 509 | + } |
| 510 | + |
| 511 | + public function testContainerCompilesWithCacheControlExpressionConfig(): void |
| 512 | + { |
| 513 | + $config = $this->getCacheControlExpressionFullConfig(); |
| 514 | + |
| 515 | + $container = $this->createContainer(); |
| 516 | + $this->extension->load([$config], $container); |
| 517 | + |
| 518 | + $container->addDefinitions(['app.expression_language' => new Definition(ExpressionLanguage::class)]); |
| 519 | + |
| 520 | + $container->compile(); |
| 521 | + |
| 522 | + $this->expectNotToPerformAssertions(); |
| 523 | + } |
| 524 | + |
492 | 525 | /**
|
493 | 526 | * Check if comma separated strings are parsed as expected.
|
494 | 527 | */
|
@@ -813,6 +846,28 @@ private function getBaseConfig(): array
|
813 | 846 | ];
|
814 | 847 | }
|
815 | 848 |
|
| 849 | + /** |
| 850 | + * @return array<string, mixed> |
| 851 | + */ |
| 852 | + private function getCacheControlExpressionFullConfig(): array |
| 853 | + { |
| 854 | + return [ |
| 855 | + 'cache_control' => [ |
| 856 | + 'rules' => [ |
| 857 | + [ |
| 858 | + 'match' => [ |
| 859 | + 'match_response' => 'foobar', |
| 860 | + 'expression_language' => 'app.expression_language', |
| 861 | + ], |
| 862 | + 'headers' => [ |
| 863 | + 'cache_control' => ['public' => true], |
| 864 | + ], |
| 865 | + ], |
| 866 | + ], |
| 867 | + ], |
| 868 | + ]; |
| 869 | + } |
| 870 | + |
816 | 871 | /**
|
817 | 872 | * @param array $methods List of methods for the matcher. Empty array to not check.
|
818 | 873 | *
|
|
0 commit comments