8000 fix processing chain adapter based cache pool · symfony/symfony@8d7fa32 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d7fa32

Browse files
committed
fix processing chain adapter based cache pool
1 parent b9a0b33 commit 8d7fa32

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ public function process(ContainerBuilder $container)
103103
if (ChainAdapter::class === $class) {
104104
$adapters = [];
105105
foreach ($adapter->getArgument(0) as $provider => $adapter) {
106-
$chainedPool = $adapter = new ChildDefinition($adapter);
106+
if ($adapter instanceof ChildDefinition) {
107+
$chainedPool = $adapter;
108+
} else {
109+
$chainedPool = $adapter = new ChildDefinition($adapter);
110+
}
111+
107112
$chainedTags = [\is_int($provider) ? [] : ['provider' => $provider]];
108113
$chainedClass = '';
109114

src/Symfony/Component/Cache/Tests/DependencyInjection/CachePoolPassTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
namespace Symfony\Component\Cache\Tests\DependencyInjection;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Cache\Adapter\ApcuAdapter;
1516
use Symfony\Component\Cache\Adapter\ArrayAdapter;
17+
use Symfony\Component\Cache\Adapter\ChainAdapter;
1618
use Symfony\Component\Cache\Adapter\RedisAdapter;
1719
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
1820
use Symfony\Component\DependencyInjection\ChildDefinition;
@@ -174,4 +176,42 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
174176

175177
$this->cachePoolPass->process($container);
176178
}
179+
180+
public function testChainAdapterPool()
181+
{
182+
$container = new ContainerBuilder();
183+
$container->setParameter('kernel.container_class', 'app');
184+
$container->setParameter('kernel.project_dir', 'foo');
185+
186+
$container->register('cache.adapter.array', ArrayAdapter::class)
187+
->addTag('cache.pool');
188+
$container->register('cache.adapter.apcu', ApcuAdapter::class)
189+
->setArguments([null, 0, null])
190+
->addTag('cache.pool');
191+
$container->register('cache.chain', ChainAdapter::class)
192+
->addArgument(['cache.adapter.array', 'cache.adapter.apcu'])
193+
->addTag('cache.pool');
194+
$container->setDefinition('cache.app', new ChildDefinition('cache.chain'))
195+
->addTag('cache.pool');
196+
$container->setDefinition('doctrine.result_cache_pool', new ChildDefinition('cache.app'))
197+
->addTag('cache.pool');
198+
199+
$this->cachePoolPass->process($container);
200+
201+
$appCachePool = $ 8000 container->getDefinition('cache.app');
202+
$this->assertInstanceOf(ChildDefinition::class, $appCachePool);
203+
$this->assertSame('cache.chain', $appCachePool->getParent());
204+
205+
$chainCachePool = $container->getDefinition('cache.chain');
206+
$this->assertNotInstanceOf(ChildDefinition::class, $chainCachePool);
207+
$this->assertCount(2, $chainCachePool->getArgument(0));
208+
$this->assertInstanceOf(ChildDefinition::class, $chainCachePool->getArgument(0)[0]);
209+
$this->assertSame('cache.adapter.array', $chainCachePool->getArgument(0)[0]->getParent());
210+
$this->assertInstanceOf(ChildDefinition::class, $chainCachePool->getArgument(0)[1]);
211+
$this->assertSame('cache.adapter.apcu', $chainCachePool->getArgument(0)[1]->getParent());
212+
213+
$doctrineCachePool = $container->getDefinition('doctrine.result_cache_pool');
214+
$this->assertInstanceOf(ChildDefinition::class, $doctrineCachePool);
215+
$this->assertSame('cache.app', $doctrineCachePool->getParent());
216+
}
177217
}

0 commit comments

Comments
 (0)
0