Skip to content

Commit d0a673d

Browse files
a.dmitryuknicolas-grekas
authored andcommitted
[Cache] Make TagAwareAdapter registrable as a service
1 parent 2205b62 commit d0a673d

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Cache\Adapter\ChainAdapter;
1717
use Symfony\Component\Cache\Adapter\NullAdapter;
1818
use Symfony\Component\Cache\Adapter\ParameterNormalizer;
19+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
1920
use Symfony\Component\Cache\Messenger\EarlyExpirationDispatcher;
2021
use Symfony\Component\DependencyInjection\ChildDefinition;
2122
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@@ -156,7 +157,7 @@ public function process(ContainerBuilder $container)
156157
),
157158
]);
158159
$pool->addTag('container.reversible');
159-
} elseif ('namespace' !== $attr || !\in_array($class, [ArrayAdapter::class, NullAdapter::class], true)) {
160+
} elseif ('namespace' !== $attr || !\in_array($class, [ArrayAdapter::class, NullAdapter::class, TagAwareAdapter::class], true)) {
160161
$argument = $tags[0][$attr];
161162

162163
if ('default_lifetime' === $attr && !is_numeric($argument)) {

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Cache\Adapter\ChainAdapter;
1818
use Symfony\Component\Cache\Adapter\NullAdapter;
1919
use Symfony\Component\Cache\Adapter\RedisAdapter;
20+
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
2021
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
2122
use Symfony\Component\DependencyInjection\ChildDefinition;
2223
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -102,15 +103,18 @@ public function testNamespaceArgumentIsSeededWithAdapterClassNameWithoutAffectin
102103
$this->assertSame('xmOJ8gqF-Y', $cachePool->getArgument(0));
103104
}
104105

105-
public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
106+
/**
107+
* @dataProvider providerAdaptersNotNamespace
108+
*/
109+
public function testNamespaceArgumentIsNotReplacedIfAdapterWithoutNamespace(string $adapterClass)
106110
{
107111
$container = new ContainerBuilder();
108112
$container->setParameter('kernel.container_class', 'app');
109113
$container->setParameter('kernel.project_dir', 'foo');
110114

111-
$container->register('cache.adapter.array', ArrayAdapter::class)->addArgument(0);
115+
$container->register('cache.adapter', $adapterClass)->addArgument(0);
112116

113-
$cachePool = new ChildDefinition('cache.adapter.array');
117+
$cachePool = new ChildDefinition('cache.adapter');
114118
$cachePool->addTag('cache.pool');
115119
$container->setDefinition('app.cache_pool', $cachePool);
116120

@@ -119,21 +123,11 @@ public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
119123
$this->assertCount(0, $container->getDefinition('app.cache_pool')->getArguments());
120124
}
121125

122-
public function testNamespaceArgumentIsNotReplacedIfNullAdapterIsUsed()
126+
public static function providerAdaptersNotNamespace(): iterable
123127
{
124-
$container = new ContainerBuilder();
125-
$container->setParameter('kernel.container_class', 'app');
126-
$container->setParameter('kernel.project_dir', 'foo');
127-
128-
$container->register('cache.adapter.null', NullAdapter::class);
129-
130-
$cachePool = new ChildDefinition('cache.adapter.null');
131-
$cachePool->addTag('cache.pool');
132-
$container->setDefinition('app.cache_pool', $cachePool);
133-
134-
$this->cachePoolPass->process($container);
135-
136-
$this->assertCount(0, $container->getDefinition('app.cache_pool')->getArguments());
128+
yield [ArrayAdapter::class];
129+
yield [NullAdapter::class];
130+
yield [TagAwareAdapter::class];
137131
}
138132

139133
public function testArgsAreReplaced()

0 commit comments

Comments
 (0)