From ad4b87bd7037a49f4bddb7a57c08b7654a2974eb Mon Sep 17 00:00:00 2001 From: Indra Gunawan Date: Fri, 30 May 2025 15:52:26 +0800 Subject: [PATCH 1/2] failing tests --- .../Fixtures/php/cache.php | 140 ++++++++++-------- .../Fixtures/xml/cache.xml | 13 ++ .../Fixtures/yml/cache.yml | 16 ++ .../FrameworkExtensionTestCase.php | 19 ++- 4 files changed, 126 insertions(+), 62 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache.php index 8b443c3c98eee..a63d2fa67660e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/cache.php @@ -1,65 +1,85 @@ loadFromExtension('framework', [ - 'annotations' => false, - 'http_method_override' => false, - 'handle_all_throwables' => true, - 'php_errors' => ['log' => true], - 'cache' => [ - 'pools' => [ - 'cache.foo' => [ - 'adapter' => 'cache.adapter.apcu', - 'default_lifetime' => 30, - ], - 'cache.baz' => [ - 'adapter' => 'cache.adapter.filesystem', - 'default_lifetime' => 7, - ], - 'cache.foobar' => [ - 'adapter' => 'cache.adapter.psr6', - 'default_lifetime' => 10, - 'provider' => 'app.cache_pool', - ], - 'cache.def' => [ - 'default_lifetime' => 'PT11S', - ], - 'cache.expr' => [ - 'default_lifetime' => '13 seconds', - ], - 'cache.chain' => [ - 'default_lifetime' => 12, - 'adapter' => [ - 'cache.adapter.array', - 'cache.adapter.filesystem', - 'redis://foo' => 'cache.adapter.redis', +namespace Symfony\Component\DependencyInjection\Loader\Configurator; + +use Symfony\Component\Cache\Adapter\ChainAdapter; + +return static function (ContainerConfigurator $container) { + $services = $container->services() + ->defaults() + ->autowire(true) + ->autoconfigure(true) + ; + + $services->set('chain_cache_custom_ns', ChainAdapter::class) + ->arg(0, ['cache.adapter.array', 'cache.adapter.filesystem']) + ->tag('cache.pool', ['namespace' => 'my-custom-ns']); + + $container->extension('framework', [ + 'annotations' => false, + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + 'cache' => [ + 'pools' => [ + 'cache.foo' => [ + 'adapter' => 'cache.adapter.apcu', + 'default_lifetime' => 30, + ], + 'cache.baz' => [ + 'adapter' => 'cache.adapter.filesystem', + 'default_lifetime' => 7, + ], + 'cache.foobar' => [ + 'adapter' => 'cache.adapter.psr6', + 'default_lifetime' => 10, + 'provider' => 'app.cache_pool', + ], + 'cache.def' => [ + 'default_lifetime' => 'PT11S', + ], + 'cache.expr' => [ + 'default_lifetime' => '13 seconds', + ], + 'cache.chain' => [ + 'default_lifetime' => 12, + 'adapter' => [ + 'cache.adapter.array', + 'cache.adapter.filesystem', + 'redis://foo' => 'cache.adapter.redis', + ], + ], + 'cache.custom_ns_chain' => [ + 'default_lifetime' => 12, + 'adapters' => ['chain_cache_custom_ns'], + ], + 'cache.ccc' => [ + 'adapter' => 'cache.adapter.array', + 'default_lifetime' => 410, + 'tags' => true, + ], + 'cache.redis_tag_aware.foo' => [ + 'adapter' => 'cache.adapter.redis_tag_aware', + ], + 'cache.redis_tag_aware.foo2' => [ + 'tags' => true, + 'adapter' => 'cache.adapter.redis_tag_aware', + ], + 'cache.redis_tag_aware.bar' => [ + 'adapter' => 'cache.redis_tag_aware.foo', + ], + 'cache.redis_tag_aware.bar2' => [ + 'tags' => true, + 'adapter' => 'cache.redis_tag_aware.foo', + ], + 'cache.redis_tag_aware.baz' => [ + 'adapter' => 'cache.redis_tag_aware.foo2', + ], + 'cache.redis_tag_aware.baz2' => [ + 'tags' => true, + 'adapter' => 'cache.redis_tag_aware.foo2', ], - ], - 'cache.ccc' => [ - 'adapter' => 'cache.adapter.array', - 'default_lifetime' => 410, - 'tags' => true, - ], - 'cache.redis_tag_aware.foo' => [ - 'adapter' => 'cache.adapter.redis_tag_aware', - ], - 'cache.redis_tag_aware.foo2' => [ - 'tags' => true, - 'adapter' => 'cache.adapter.redis_tag_aware', - ], - 'cache.redis_tag_aware.bar' => [ - 'adapter' => 'cache.redis_tag_aware.foo', - ], - 'cache.redis_tag_aware.bar2' => [ - 'tags' => true, - 'adapter' => 'cache.redis_tag_aware.foo', - ], - 'cache.redis_tag_aware.baz' => [ - 'adapter' => 'cache.redis_tag_aware.foo2', - ], - 'cache.redis_tag_aware.baz2' => [ - 'tags' => true, - 'adapter' => 'cache.redis_tag_aware.foo2', ], ], - ], -]); + ]); +}; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache.xml index b4625a26d2bda..b9074041daea5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/cache.xml @@ -5,6 +5,18 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> + + + + + + + + + + + + @@ -19,6 +31,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache.yml index e88c77f1c38b7..667279b2121d8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/cache.yml @@ -1,3 +1,16 @@ +services: + _defaults: + autowire: true + autoconfigure: true + + chain_cache_custom_ns: + class: Symfony\Component\Cache\Adapter\ChainAdapter + arguments: + - ['@cache.adapter.array', '@cache.adapter.filesystem'] + tags: + - { name: cache.pool, namespace: 'my-custom-ns' } + + framework: annotations: false http_method_override: false @@ -26,6 +39,9 @@ framework: - cache.adapter.array - cache.adapter.filesystem - {name: cache.adapter.redis, provider: 'redis://foo'} + cache.custom_ns_chain: + default_lifetime: 12 + adapter: 'chain_cache_custom_ns' cache.ccc: adapter: cache.adapter.array default_lifetime: 410 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php index 7f94b83ce58c4..15f912f71c306 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -1752,6 +1752,7 @@ public function testCachePoolServices() { $container = $this->createContainerFromFile('cache', [], true, false); $container->setParameter('cache.prefix.seed', 'test'); + $container->addCompilerPass(new ResolveInstanceofConditionalsPass()); $container->addCompilerPass(new CachePoolPass()); $container->compile(); @@ -1762,9 +1763,7 @@ public function testCachePoolServices() $this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.expr', 'cache.app', '13 seconds'); $chain = $container->getDefinition('cache.chain'); - $this->assertSame(ChainAdapter::class, $chain->getClass()); - $this->assertCount(2, $chain->getArguments()); $this->assertCount(3, $chain->getArguments()[0]); @@ -1785,6 +1784,22 @@ public function testCachePoolServices() ]; $this->assertEquals($expected, $chain->getArguments()); + $chainCustomNs = $container->getDefinition('cache.custom_ns_chain'); + $this->assertCount(2, $chainCustomNs->getArguments()); + $this->assertCount(2, $chainCustomNs->getArguments()['index_0']); + + $expectedCustomNsChain = [ + 'index_0' => [ + (new ChildDefinition('cache.adapter.array')) + ->replaceArgument(0, 12), + (new ChildDefinition('cache.adapter.filesystem')) + ->replaceArgument(0, 'my-custom-ns') + ->replaceArgument(1, 12), + ], + 'index_1' => 12, + ]; + $this->assertEquals($expectedCustomNsChain, $chainCustomNs->getArguments()); + // Test "tags: true" wrapping logic $tagAwareDefinition = $container->getDefinition('cache.ccc'); $this->assertSame(TagAwareAdapter::class, $tagAwareDefinition->getClass()); From 8e3d1490d95d37e31ae5d648911da3c7095f88fa Mon Sep 17 00:00:00 2001 From: Indra Gunawan Date: Sat, 31 May 2025 20:08:15 +0800 Subject: [PATCH 2/2] fix CachePoolPass --- .../Component/Cache/DependencyInjection/CachePoolPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php index 90c089074ef4b..4c3f6fe1bc98f 100644 --- a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php +++ b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php @@ -58,7 +58,7 @@ public function process(ContainerBuilder $container) continue; } $class = $adapter->getClass(); - while ($adapter instanceof ChildDefinition) { + while (ChainAdapter::class !== $class && $adapter instanceof ChildDefinition) { $adapter = $container->findDefinition($adapter->getParent()); $class = $class ?: $adapter->getClass(); if ($t = $adapter->getTag('cache.pool')) {