From 29ba7a8cf1690efc33a634b8ddd9a1296b60e7b7 Mon Sep 17 00:00:00 2001 From: Ruud Arentsen Date: Fri, 13 Sep 2019 12:59:08 +0200 Subject: [PATCH] Fixed cache pools affecting each other due to an overwritten seed variable --- .../DependencyInjection/CachePoolPass.php | 5 ++-- .../DependencyInjection/CachePoolPassTest.php | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php index 5d7a2369c2..eef9e75b06 100644 --- a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php +++ b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php @@ -78,11 +78,12 @@ class CachePoolPass implements CompilerPassInterface } $name = $tags[0]['name'] ?? $id; if (!isset($tags[0]['namespace'])) { + $namespaceSeed = $seed; if (null !== $class) { - $seed .= '.'.$class; + $namespaceSeed .= '.'.$class; } - $tags[0]['namespace'] = $this->getNamespace($seed, $name); + $tags[0]['namespace'] = $this->getNamespace($namespaceSeed, $name); } if (isset($tags[0]['clearer'])) { $clearer = $tags[0]['clearer']; diff --git a/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php b/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php index 85b7e64b1c..e763dabe48 100644 --- a/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php +++ b/src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php @@ -70,6 +70,33 @@ class CachePoolPassTest extends TestCase $this->assertSame('xmOJ8gqF-Y', $cachePool->getArgument(0)); } + public function testNamespaceArgumentIsSeededWithAdapterClassNameWithoutAffectingOtherCachePools() + { + $container = new ContainerBuilder(); + $container->setParameter('kernel.container_class', 'app'); + $container->setParameter('kernel.project_dir', 'foo'); + $adapter = new Definition(); + $adapter->setAbstract(true); + $adapter->addTag('cache.pool'); + $adapter->setClass(RedisAdapter::class); + $container->setDefinition('app.cache_adapter', $adapter); + $container->setAlias('app.cache_adapter_alias', 'app.cache_adapter'); + + $otherCachePool = new ChildDefinition('app.cache_adapter_alias'); + $otherCachePool->addArgument(null); + $otherCachePool->addTag('cache.pool'); + $container->setDefinition('app.other_cache_pool', $otherCachePool); + + $cachePool = new ChildDefinition('app.cache_adapter_alias'); + $cachePool->addArgument(null); + $cachePool->addTag('cache.pool'); + $container->setDefinition('app.cache_pool', $cachePool); + + $this->cachePoolPass->process($container); + + $this->assertSame('xmOJ8gqF-Y', $cachePool->getArgument(0)); + } + public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed() { $container = new ContainerBuilder();