diff --git a/DependencyInjection/Compiler/CacheCompatibilityPass.php b/DependencyInjection/Compiler/CacheCompatibilityPass.php index 64b02a770..3e4489f86 100644 --- a/DependencyInjection/Compiler/CacheCompatibilityPass.php +++ b/DependencyInjection/Compiler/CacheCompatibilityPass.php @@ -6,6 +6,7 @@ use Doctrine\Common\Cache\Psr6\CacheAdapter; use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Psr\Cache\CacheItemPoolInterface; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -34,10 +35,14 @@ public function process(ContainerBuilder $container): void $aliasId = (string) $methodCall[1][0]; $definitionId = (string) $container->getAlias($aliasId); - $isPsr6 = is_a($container->getDefinition($definitionId)->getClass(), CacheItemPoolInterface::class, true); + $definition = $container->getDefinition($definitionId); $shouldBePsr6 = self::CACHE_METHODS_PSR6_SUPPORT_MAP[$methodCall[0]]; - if ($shouldBePsr6 === $isPsr6) { + while (! $definition->getClass() && $definition instanceof ChildDefinition) { + $definition = $container->findDefinition($definition->getParent()); + } + + if ($shouldBePsr6 === is_a($definition->getClass(), CacheItemPoolInterface::class, true)) { continue; } diff --git a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php index f9b1ee544..1d0c4ae11 100644 --- a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php +++ b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php @@ -15,7 +15,7 @@ class CacheCompatibilityPassTest extends TestCase { use ExpectDeprecationTrait; - public function testLegacyCacheConfigUsingServiceDefinedByApplication(): void + public function testCacheConfigUsingServiceDefinedByApplication(): void { $this->expectNotToPerformAssertions(); (new class () extends TestKernel { @@ -23,9 +23,21 @@ public function registerContainerConfiguration(LoaderInterface $loader): void { parent::registerContainerConfiguration($loader); $loader->load(static function (ContainerBuilder $containerBuilder): void { + $containerBuilder->loadFromExtension('framework', [ + 'cache' => [ + 'pools' => [ + 'doctrine.system_cache_pool' => ['adapter' => 'cache.system'], + ], + ], + ]); $containerBuilder->loadFromExtension( 'doctrine', - ['orm' => ['query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]] + [ + 'orm' => [ + 'query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service'], + 'result_cache_driver' => ['type' => 'pool', 'pool' => 'doctrine.system_cache_pool'], + ], + ] ); $containerBuilder->setDefinition( 'custom_cache_service', @@ -61,7 +73,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void } /** @group legacy */ - public function testMetdataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): void + public function testMetadataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): void { $this->expectDeprecation('Since doctrine/doctrine-bundle 2.4: Configuring doctrine/cache is deprecated. Please update the cache service "custom_cache_service" to use a PSR-6 cache.'); (new class (false) extends TestKernel {