|
12 | 12 | namespace Symfony\Component\Cache\Tests\DependencyInjection;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Component\Cache\Adapter\ApcuAdapter; |
15 | 16 | use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
| 17 | +use Symfony\Component\Cache\Adapter\ChainAdapter; |
16 | 18 | use Symfony\Component\Cache\Adapter\RedisAdapter;
|
17 | 19 | use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
|
18 | 20 | use Symfony\Component\DependencyInjection\ChildDefinition;
|
@@ -174,4 +176,42 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
|
174 | 176 |
|
175 | 177 | $this->cachePoolPass->process($container);
|
176 | 178 | }
|
| 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 | + } |
177 | 217 | }
|
0 commit comments