Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cache compatibility with cache pools #1360

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions DependencyInjection/Compiler/CacheCompatibilityPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\Common\Cache\Psr6\CacheAdapter;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -34,10 +35,14 @@ public function process(ContainerBuilder $container): void

$aliasId = (string) $methodCall[1][0];
$definitionId = (string) $container->getAlias($aliasId);
$isPsr6 = is_a($container->getDefinition($definitionId)->getClass(), CacheItemPoolInterface::class, true);
$definition = $container->getDefinition($definitionId);
$shouldBePsr6 = self::CACHE_METHODS_PSR6_SUPPORT_MAP[$methodCall[0]];

if ($shouldBePsr6 === $isPsr6) {
while (! $definition->getClass() && $definition instanceof ChildDefinition) {
$definition = $container->findDefinition($definition->getParent());
}

if ($shouldBePsr6 === is_a($definition->getClass(), CacheItemPoolInterface::class, true)) {
continue;
}

Expand Down
18 changes: 15 additions & 3 deletions Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,29 @@ class CacheCompatibilityPassTest extends TestCase
{
use ExpectDeprecationTrait;

public function testLegacyCacheConfigUsingServiceDefinedByApplication(): void
public function testCacheConfigUsingServiceDefinedByApplication(): void
{
$this->expectNotToPerformAssertions();
(new class () extends TestKernel {
public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);
$loader->load(static function (ContainerBuilder $containerBuilder): void {
$containerBuilder->loadFromExtension('framework', [
'cache' => [
'pools' => [
'doctrine.system_cache_pool' => ['adapter' => 'cache.system'],
],
],
]);
$containerBuilder->loadFromExtension(
'doctrine',
['orm' => ['query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]]
[
'orm' => [
'query_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service'],
'result_cache_driver' => ['type' => 'pool', 'pool' => 'doctrine.system_cache_pool'],
],
]
);
$containerBuilder->setDefinition(
'custom_cache_service',
Expand Down Expand Up @@ -61,7 +73,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
}

/** @group legacy */
public function testMetdataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): void
public function testMetadataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): void
{
$this->expectDeprecation('Since doctrine/doctrine-bundle 2.4: Configuring doctrine/cache is deprecated. Please update the cache service "custom_cache_service" to use a PSR-6 cache.');
(new class (false) extends TestKernel {
Expand Down