From c4998e5c945ac9f0d739943f9854c82d99f0276c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Sun, 14 Nov 2021 17:57:24 +0100 Subject: [PATCH] Exclude custom region classes from CacheCompatibilityPass --- .../Compiler/CacheCompatibilityPass.php | 9 ++++++++- .../Compiler/CacheCompatibilityPassTest.php | 20 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/Compiler/CacheCompatibilityPass.php b/DependencyInjection/Compiler/CacheCompatibilityPass.php index e5a88e904..5574048ba 100644 --- a/DependencyInjection/Compiler/CacheCompatibilityPass.php +++ b/DependencyInjection/Compiler/CacheCompatibilityPass.php @@ -65,7 +65,14 @@ private function updateSecondLevelCache(ContainerBuilder $container, Definition continue; } - $driverId = (string) $container->getDefinition($factoryMethodCall[1][0])->getArgument(1); + $regionDefinition = $container->getDefinition($factoryMethodCall[1][0]); + + // We don't know how to adjust custom region classes + if ($regionDefinition->getClass() !== '%doctrine.orm.second_level_cache.default_region.class%') { + continue; + } + + $driverId = (string) $regionDefinition->getArgument(1); if (! $container->hasAlias($driverId)) { continue; } diff --git a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php index f0aa01101..49ec36336 100644 --- a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php +++ b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php @@ -5,23 +5,37 @@ use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\TestKernel; use Doctrine\Bundle\DoctrineBundle\Tests\TestCase; use Doctrine\Common\Cache\Psr6\DoctrineProvider; +use Doctrine\ORM\Cache\Region; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use function get_class; + class CacheCompatibilityPassTest extends TestCase { use ExpectDeprecationTrait; public function testCacheConfigUsingServiceDefinedByApplication(): void { - (new class () extends TestKernel { + $customRegionClass = get_class($this->createMock(Region::class)); + + (new class ($customRegionClass) extends TestKernel { + /** @var string */ + private $regionClass; + + public function __construct(string $regionClass) + { + parent::__construct(false); + $this->regionClass = $regionClass; + } + public function registerContainerConfiguration(LoaderInterface $loader): void { parent::registerContainerConfiguration($loader); - $loader->load(static function (ContainerBuilder $containerBuilder): void { + $loader->load(function (ContainerBuilder $containerBuilder): void { $containerBuilder->loadFromExtension('framework', [ 'cache' => [ 'pools' => [ @@ -39,11 +53,13 @@ public function registerContainerConfiguration(LoaderInterface $loader): void 'enabled' => true, 'regions' => [ 'lifelong' => ['lifetime' => 0, 'cache_driver' => ['type' => 'pool', 'pool' => 'doctrine.system_cache_pool']], + 'entity_cache_region' => ['type' => 'service', 'service' => $this->regionClass], ], ], ], ] ); + $containerBuilder->register($this->regionClass, $this->regionClass); $containerBuilder->setDefinition( 'custom_cache_service', (new Definition(DoctrineProvider::class))