diff --git a/DependencyInjection/Compiler/CacheCompatibilitPass.php b/DependencyInjection/Compiler/CacheCompatibilitPass.php new file mode 100644 index 000000000..0f6e9ee6f --- /dev/null +++ b/DependencyInjection/Compiler/CacheCompatibilitPass.php @@ -0,0 +1,65 @@ + true, + 'setQueryCacheImpl' => false, + 'setResultCacheImpl' => false, + ]; + + public function process(ContainerBuilder $container): void + { + foreach (array_keys($container->findTaggedServiceIds(IdGeneratorPass::CONFIGURATION_TAG)) as $id) { + foreach ($container->getDefinition($id)->getMethodCalls() as $methodCall) { + if (! isset(self::CACHE_METHODS_PSR6_SUPPORT_MAP[$methodCall[0]])) { + continue; + } + + $aliasId = (string) $methodCall[1][0]; + $definitionId = (string) $container->getAlias($aliasId); + $isPsr6 = is_a($container->getDefinition($definitionId)->getClass(), CacheItemPoolInterface::class, true); + $shouldBePsr6 = self::CACHE_METHODS_PSR6_SUPPORT_MAP[$methodCall[0]]; + + if ($shouldBePsr6 === $isPsr6) { + continue; + } + + $targetClass = CacheProvider::class; + $targetFactory = DoctrineProvider::class; + + if ($shouldBePsr6) { + $targetClass = CacheItemPoolInterface::class; + $targetFactory = CacheAdapter::class; + + trigger_deprecation( + 'doctrine/doctrine-bundle', + '2.4', + 'Configuring doctrine/cache is deprecated. Please update the cache service "%s" to use a PSR-6 cache.', + $definitionId + ); + } + + $container->setDefinition($aliasId, (new Definition($targetClass)) + ->setFactory([$targetFactory, 'wrap']) + ->addArgument(new Reference($definitionId))); + } + } + } +} diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 21555ed04..f5de9f751 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -724,7 +724,6 @@ private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition ->scalarNode('type')->defaultNull()->end() ->scalarNode('id')->end() ->scalarNode('pool')->end() - ->booleanNode('is_psr6')->defaultFalse()->end() ->end(); if ($name === 'metadata_cache_driver') { diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index 13f4e8ed3..9d9605046 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -11,9 +11,6 @@ use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; -use Doctrine\Common\Cache\CacheProvider; -use Doctrine\Common\Cache\Psr6\CacheAdapter; -use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connections\MasterSlaveConnection; use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection; @@ -26,7 +23,6 @@ use Doctrine\ORM\Proxy\Autoloader; use Doctrine\ORM\UnitOfWork; use LogicException; -use Psr\Cache\CacheItemPoolInterface; use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension; use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator; use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator; @@ -60,7 +56,6 @@ use function reset; use function sprintf; use function str_replace; -use function trigger_deprecation; /** * DoctrineExtension is an extension for the Doctrine DBAL and ORM library. @@ -883,31 +878,17 @@ protected function getMappingResourceExtension(): string /** * {@inheritDoc} */ - protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriver, ContainerBuilder $container, bool $usePsr6 = false): string + protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriver, ContainerBuilder $container): string { $aliasId = $this->getObjectManagerElementName(sprintf('%s_%s', $objectManagerName, $cacheName)); switch ($cacheDriver['type'] ?? 'pool') { case 'service': $serviceId = $cacheDriver['id']; - $isPsr6 = $cacheDriver['is_psr6']; - - if (! $isPsr6) { - trigger_deprecation( - 'doctrine/doctrine-bundle', - '2.4', - 'Configuring doctrine/cache is deprecated. Please update the cache service "%s" for entity manager "%s" to use a PSR-6 cache.', - $serviceId, - $objectManagerName - ); - } - break; case 'pool': - $pool = $cacheDriver['pool'] ?? $this->createArrayAdapterCachePool($container, $objectManagerName, $cacheName); - $serviceId = $pool; - $isPsr6 = true; + $serviceId = $cacheDriver['pool'] ?? $this->createArrayAdapterCachePool($container, $objectManagerName, $cacheName); break; default: @@ -919,27 +900,6 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD )); } - $cacheName = str_replace('_cache', '', $cacheName); - - // Create a wrapper as required - if ($isPsr6 && ! $usePsr6) { - $wrappedServiceId = sprintf('doctrine.orm.cache.provider.%s.%s', $objectManagerName, $cacheName); - - $definition = $container->register($wrappedServiceId, CacheProvider::class); - $definition->setFactory([DoctrineProvider::class, 'wrap']); - $definition->addArgument(new Reference($serviceId)); - - $serviceId = $wrappedServiceId; - } elseif (! $isPsr6 && $usePsr6) { - $wrappedServiceId = sprintf('cache.doctrine.orm.adapter.%s.%s', $objectManagerName, $cacheName); - - $definition = $container->register($wrappedServiceId, CacheItemPoolInterface::class); - $definition->setFactory([CacheAdapter::class, 'wrap']); - $definition->addArgument(new Reference($serviceId)); - - $serviceId = $wrappedServiceId; - } - $container->setAlias($aliasId, new Alias($serviceId, false)); return $aliasId; @@ -952,9 +912,9 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD */ protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $container) { - $this->loadCacheDriver('metadata_cache', $entityManager['name'], $entityManager['metadata_cache_driver'], $container, true); - $this->loadCacheDriver('result_cache', $entityManager['name'], $entityManager['result_cache_driver'], $container, false); - $this->loadCacheDriver('query_cache', $entityManager['name'], $entityManager['query_cache_driver'], $container, false); + $this->loadCacheDriver('metadata_cache', $entityManager['name'], $entityManager['metadata_cache_driver'], $container); + $this->loadCacheDriver('result_cache', $entityManager['name'], $entityManager['result_cache_driver'], $container); + $this->loadCacheDriver('query_cache', $entityManager['name'], $entityManager['query_cache_driver'], $container); if ($container->getParameter('kernel.debug')) { return; diff --git a/DoctrineBundle.php b/DoctrineBundle.php index 2088d0fff..1ba591cc5 100644 --- a/DoctrineBundle.php +++ b/DoctrineBundle.php @@ -2,6 +2,7 @@ namespace Doctrine\Bundle\DoctrineBundle; +use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheCompatibilitPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheSchemaSubscriberPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DbalSchemaFilterPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\EntityListenerPass; @@ -48,6 +49,7 @@ public function build(ContainerBuilder $container) } } + $container->addCompilerPass(new CacheCompatibilitPass()); $container->addCompilerPass(new DoctrineValidationPass('orm')); $container->addCompilerPass(new EntityListenerPass()); $container->addCompilerPass(new ServiceRepositoryCompilerPass()); diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 61ca1a4aa..36bc76313 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -3,10 +3,12 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection; use Doctrine\Bundle\DoctrineBundle\Dbal\BlacklistSchemaAssetFilter; +use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheCompatibilitPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DbalSchemaFilterPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\EntityListenerPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\WellKnownSchemaFilterPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; +use Doctrine\Common\Cache\CacheProvider; use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connections\MasterSlaveConnection; @@ -432,17 +434,13 @@ public function testLoadMultipleConnections(): void $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_metadata_cache')); $this->assertEquals(PhpArrayAdapter::class, $definition->getClass()); - $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_query_cache')); + $definition = $container->getDefinition('doctrine.orm.em1_query_cache'); + $this->assertEquals(CacheProvider::class, $definition->getClass()); $this->assertEquals([DoctrineProvider::class, 'wrap'], $definition->getFactory()); - $arguments = $definition->getArguments(); - $this->assertInstanceOf(Reference::class, $arguments[0]); - $this->assertEquals('cache.doctrine.orm.em1.query', (string) $arguments[0]); - $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.em1_result_cache')); + $definition = $container->getDefinition('doctrine.orm.em1_result_cache'); + $this->assertEquals(CacheProvider::class, $definition->getClass()); $this->assertEquals([DoctrineProvider::class, 'wrap'], $definition->getFactory()); - $arguments = $definition->getArguments(); - $this->assertInstanceOf(Reference::class, $arguments[0]); - $this->assertEquals('cache.doctrine.orm.em1.result', (string) $arguments[0]); } public function testLoadLogging(): void @@ -719,7 +717,7 @@ public function testSecondLevelCache(): void $this->assertDICDefinitionClass($myEntityRegionDef, '%doctrine.orm.second_level_cache.default_region.class%'); $this->assertDICDefinitionClass($loggerChainDef, '%doctrine.orm.second_level_cache.logger_chain.class%'); $this->assertDICDefinitionClass($loggerStatisticsDef, '%doctrine.orm.second_level_cache.logger_statistics.class%'); - $this->assertEquals([DoctrineProvider::class, 'wrap'], $cacheDriverDef->getFactory()); + $this->assertDICDefinitionClass($cacheDriverDef, ArrayAdapter::class); $this->assertDICDefinitionMethodCallOnce($configDef, 'setSecondLevelCacheConfiguration'); $this->assertDICDefinitionMethodCallCount($slcFactoryDef, 'setRegion', [], 3); $this->assertDICDefinitionMethodCallCount($loggerChainDef, 'setLogger', [], 3); @@ -1438,8 +1436,10 @@ private function assertDICDefinitionNoMethodCall( private function compileContainer(ContainerBuilder $container): void { - $container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]); - $container->getCompilerPassConfig()->setRemovingPasses([]); + $passConfig = $container->getCompilerPassConfig(); + $passConfig->setOptimizationPasses([new ResolveChildDefinitionsPass()]); + $passConfig->setRemovingPasses([]); + $passConfig->addPass(new CacheCompatibilitPass()); $container->compile(); } } diff --git a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php new file mode 100644 index 000000000..2b4b803b7 --- /dev/null +++ b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php @@ -0,0 +1,86 @@ +expectNotToPerformAssertions(); + (new class () extends TestKernel { + public function registerContainerConfiguration(LoaderInterface $loader): void + { + parent::registerContainerConfiguration($loader); + $loader->load(static function (ContainerBuilder $containerBuilder): void { + $containerBuilder->loadFromExtension( + 'doctrine', + ['orm' => ['query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]] + ); + $containerBuilder->setDefinition( + 'custom_cache_service', + (new Definition(DoctrineProvider::class)) + ->setArguments([new Definition(ArrayAdapter::class)]) + ->setFactory([DoctrineProvider::class, 'wrap']) + ); + }); + } + })->boot(); + } + + /** @group legacy */ + public function testMetadataCacheConfigUsingPsr6ServiceDefinedByApplication(): void + { + $this->expectDeprecation('%aThe "metadata_cache_driver" configuration key is deprecated.%a'); + (new class () extends TestKernel { + public function registerContainerConfiguration(LoaderInterface $loader): void + { + parent::registerContainerConfiguration($loader); + $loader->load(static function (ContainerBuilder $containerBuilder): void { + $containerBuilder->loadFromExtension( + 'doctrine', + ['orm' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]] + ); + $containerBuilder->setDefinition( + 'custom_cache_service', + new Definition(ArrayAdapter::class) + ); + }); + } + })->boot(); + } + + /** @group legacy */ + public function testMetdataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): 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 () extends TestKernel { + public function registerContainerConfiguration(LoaderInterface $loader): void + { + parent::registerContainerConfiguration($loader); + $loader->load(static function (ContainerBuilder $containerBuilder): void { + $containerBuilder->loadFromExtension( + 'doctrine', + ['orm' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]] + ); + $containerBuilder->setDefinition( + 'custom_cache_service', + (new Definition(DoctrineProvider::class)) + ->setArguments([new Definition(ArrayAdapter::class)]) + ->setFactory([DoctrineProvider::class, 'wrap']) + ); + }); + } + })->boot(); + } +} diff --git a/Tests/CustomIdGeneratorTest.php b/Tests/DependencyInjection/Compiler/IdGeneratorPassTest.php similarity index 90% rename from Tests/CustomIdGeneratorTest.php rename to Tests/DependencyInjection/Compiler/IdGeneratorPassTest.php index 217f5f67e..712ab1e24 100644 --- a/Tests/CustomIdGeneratorTest.php +++ b/Tests/DependencyInjection/Compiler/IdGeneratorPassTest.php @@ -1,7 +1,8 @@ [ 'AnnotationsBundle' => [ 'type' => 'annotation', - 'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Entity', + 'dir' => __DIR__ . '/../Fixtures/Bundles/AnnotationsBundle/Entity', 'prefix' => 'Fixtures\Bundles\AnnotationsBundle\Entity', ], ], @@ -78,6 +79,7 @@ public function testRepositoryServiceWiring(): void $def->setAutoconfigured(true); + $container->addCompilerPass(new CacheCompatibilitPass()); $container->addCompilerPass(new IdGeneratorPass()); $container->compile(); diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index c9e99c02d..7a86129bc 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -8,9 +8,7 @@ use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; use Doctrine\Bundle\DoctrineBundle\Tests\Builder\BundleConfigurationBuilder; use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\Php8EntityListener; -use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\TestKernel; use Doctrine\Common\Cache\Cache; -use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Sharding\PoolingShardManager; @@ -24,7 +22,6 @@ use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\PhpArrayAdapter; -use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -463,18 +460,10 @@ public function testDependencyInjectionConfigurationDefaults(): void $this->assertSame(ArrayAdapter::class, $definition->getClass()); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_query_cache')); - $this->assertEquals([DoctrineProvider::class, 'wrap'], $definition->getFactory()); - $arguments = $definition->getArguments(); - $this->assertInstanceOf(Reference::class, $arguments[0]); - $this->assertEquals('cache.doctrine.orm.default.query', (string) $arguments[0]); - $this->assertSame(ArrayAdapter::class, $container->getDefinition((string) $arguments[0])->getClass()); + $this->assertEquals(ArrayAdapter::class, $definition->getClass()); $definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_result_cache')); - $this->assertEquals([DoctrineProvider::class, 'wrap'], $definition->getFactory()); - $arguments = $definition->getArguments(); - $this->assertInstanceOf(Reference::class, $arguments[0]); - $this->assertEquals('cache.doctrine.orm.default.result', (string) $arguments[0]); - $this->assertSame(ArrayAdapter::class, $container->getDefinition((string) $arguments[0])->getClass()); + $this->assertSame(ArrayAdapter::class, $definition->getClass()); } public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection(): void @@ -591,7 +580,7 @@ public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration() $configurationArray = BundleConfigurationBuilder::createBuilderWithBaseValues() ->addSecondLevelCache([ - 'region_cache_driver' => ['type' => 'service', 'id' => 'my_pool'], + 'region_cache_driver' => ['type' => 'service', 'id' => 'my_cache'], 'regions' => [ 'hour_region' => ['lifetime' => 3600], ], @@ -930,57 +919,12 @@ public function testInvalidCacheConfiguration(): void $extension->load([$config], $container); } - public function testLegacyCacheConfigUsingServiceDefinedByApplication(): void - { - $this->expectNotToPerformAssertions(); - (new class () extends TestKernel { - public function registerContainerConfiguration(LoaderInterface $loader): void - { - parent::registerContainerConfiguration($loader); - $loader->load(static function (ContainerBuilder $containerBuilder): void { - $containerBuilder->loadFromExtension( - 'doctrine', - ['orm' => ['query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]] - ); - $containerBuilder->setDefinition( - 'custom_cache_service', - (new Definition(DoctrineProvider::class)) - ->setArguments([new Definition(ArrayAdapter::class)]) - ->setFactory([DoctrineProvider::class, 'wrap']) - ); - }); - } - })->boot(); - } - - /** @group legacy */ - public function testCacheConfigUsingServiceDefinedByApplication(): void - { - $this->expectNotToPerformAssertions(); - (new class () extends TestKernel { - public function registerContainerConfiguration(LoaderInterface $loader): void - { - parent::registerContainerConfiguration($loader); - $loader->load(static function (ContainerBuilder $containerBuilder): void { - $containerBuilder->loadFromExtension( - 'doctrine', - ['orm' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service', 'is_psr6' => true]]] - ); - $containerBuilder->setDefinition( - 'custom_cache_service', - new Definition(ArrayAdapter::class) - ); - }); - } - })->boot(); - } - /** * @param array{pool?: string, type: ?string} $cacheConfig * * @dataProvider cacheConfigurationProvider */ - public function testCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, $cacheConfig): void + public function testCacheConfiguration(?string $expectedAliasName, string $expectedTarget, string $cacheName, $cacheConfig): void { if (! interface_exists(EntityManagerInterface::class)) { self::markTestSkipped('This test requires ORM'); @@ -996,9 +940,13 @@ public function testCacheConfiguration(string $expectedAliasName, string $expect $extension->load([$config], $container); - $this->assertTrue($container->hasAlias($expectedAliasName)); - $alias = $container->getAlias($expectedAliasName); - $this->assertEquals($expectedAliasTarget, (string) $alias); + if ($expectedAliasName) { + $this->assertTrue($container->hasAlias($expectedAliasName)); + $alias = $container->getAlias($expectedAliasName); + $this->assertEquals($expectedTarget, (string) $alias); + } else { + $this->assertTrue($container->hasDefinition($expectedTarget)); + } } /** @@ -1030,16 +978,10 @@ public static function legacyCacheConfigurationProvider(): array ], 'metadata_cache_service' => [ 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', - 'expectedAliasTarget' => 'cache.doctrine.orm.adapter.default.metadata.php_array', + 'expectedAliasTarget' => 'service_target_metadata.php_array', 'cacheName' => 'metadata_cache_driver', 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_metadata'], ], - 'metadata_psr6_service' => [ - 'expectedAliasName' => 'doctrine.orm.default_metadata_cache', - 'expectedAliasTarget' => 'service_target_metadata_psr6.php_array', - 'cacheName' => 'metadata_cache_driver', - 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_metadata_psr6', 'is_psr6' => true], - ], 'query_cache_service' => [ 'expectedAliasName' => 'doctrine.orm.default_query_cache', 'expectedAliasTarget' => 'service_target_query', @@ -1055,45 +997,45 @@ public static function legacyCacheConfigurationProvider(): array ]; } - /** @return array> */ + /** @return array> */ public static function cacheConfigurationProvider(): array { return [ 'query_cache_default' => [ - 'expectedAliasName' => 'doctrine.orm.default_query_cache', - 'expectedAliasTarget' => 'doctrine.orm.cache.provider.default.query', + 'expectedAliasName' => null, + 'expectedTarget' => 'cache.doctrine.orm.default.query', 'cacheName' => 'query_cache_driver', 'cacheConfig' => ['type' => null], ], 'result_cache_default' => [ - 'expectedAliasName' => 'doctrine.orm.default_result_cache', - 'expectedAliasTarget' => 'doctrine.orm.cache.provider.default.result', + 'expectedAliasName' => null, + 'expectedTarget' => 'cache.doctrine.orm.default.result', 'cacheName' => 'result_cache_driver', 'cacheConfig' => ['type' => null], ], 'query_cache_pool' => [ 'expectedAliasName' => 'doctrine.orm.default_query_cache', - 'expectedAliasTarget' => 'doctrine.orm.cache.provider.default.query', + 'expectedTarget' => 'query_cache_pool', 'cacheName' => 'query_cache_driver', 'cacheConfig' => ['type' => 'pool', 'pool' => 'query_cache_pool'], ], 'result_cache_pool' => [ 'expectedAliasName' => 'doctrine.orm.default_result_cache', - 'expectedAliasTarget' => 'doctrine.orm.cache.provider.default.result', + 'expectedTarget' => 'result_cache_pool', 'cacheName' => 'result_cache_driver', 'cacheConfig' => ['type' => 'pool', 'pool' => 'result_cache_pool'], ], 'query_cache_service' => [ 'expectedAliasName' => 'doctrine.orm.default_query_cache', - 'expectedAliasTarget' => 'doctrine.orm.cache.provider.default.query', + 'expectedTarget' => 'service_target_query', 'cacheName' => 'query_cache_driver', - 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_query', 'is_psr6' => true], + 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_query'], ], 'result_cache_service' => [ 'expectedAliasName' => 'doctrine.orm.default_result_cache', - 'expectedAliasTarget' => 'doctrine.orm.cache.provider.default.result', + 'expectedTarget' => 'service_target_result', 'cacheName' => 'result_cache_driver', - 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_result', 'is_psr6' => true], + 'cacheConfig' => ['type' => 'service', 'id' => 'service_target_result'], ], ]; } diff --git a/Tests/ServiceRepositoryTest.php b/Tests/ServiceRepositoryTest.php index a55658379..0d8038aa2 100644 --- a/Tests/ServiceRepositoryTest.php +++ b/Tests/ServiceRepositoryTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests; +use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheCompatibilitPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; use Doctrine\Common\Annotations\AnnotationReader; @@ -87,6 +88,7 @@ public function testRepositoryServiceWiring(): void $def->setAutoconfigured(true); $container->addCompilerPass(new ServiceRepositoryCompilerPass()); + $container->addCompilerPass(new CacheCompatibilitPass()); $container->compile(); $em = $container->get('doctrine.orm.default_entity_manager'); diff --git a/Tests/TestCase.php b/Tests/TestCase.php index a5a5117cf..f86c22686 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -2,6 +2,7 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests; +use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheCompatibilitPass; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType; use Doctrine\Common\Annotations\AnnotationReader; @@ -74,10 +75,13 @@ public function createXmlBundleTestContainer(): ContainerBuilder $container->setDefinition('cache.system', (new Definition(ArrayAdapter::class))->setPublic(true)); $container->setDefinition('cache.app', (new Definition(ArrayAdapter::class))->setPublic(true)); - $container->getCompilerPassConfig()->setOptimizationPasses([new ResolveChildDefinitionsPass()]); - $container->getCompilerPassConfig()->setRemovingPasses([]); + $compilerPassConfig = $container->getCompilerPassConfig(); + + $compilerPassConfig->setOptimizationPasses([new ResolveChildDefinitionsPass()]); + $compilerPassConfig->setRemovingPasses([]); + $compilerPassConfig->addPass(new CacheCompatibilitPass()); // make all Doctrine services public, so we can fetch them in the test - $container->getCompilerPassConfig()->addPass(new TestCaseAllPublicCompilerPass()); + $compilerPassConfig->addPass(new TestCaseAllPublicCompilerPass()); $container->compile(); return $container;