Skip to content

Commit

Permalink
Exclude custom region classes from CacheCompatibilityPass
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Nov 16, 2021
1 parent ae07283 commit c4998e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 8 additions & 1 deletion DependencyInjection/Compiler/CacheCompatibilityPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ private function updateSecondLevelCache(ContainerBuilder $container, Definition
continue;
}

$driverId = (string) $container->getDefinition($factoryMethodCall[1][0])->getArgument(1);
$regionDefinition = $container->getDefinition($factoryMethodCall[1][0]);

// We don't know how to adjust custom region classes
if ($regionDefinition->getClass() !== '%doctrine.orm.second_level_cache.default_region.class%') {
continue;
}

$driverId = (string) $regionDefinition->getArgument(1);
if (! $container->hasAlias($driverId)) {
continue;
}
Expand Down
20 changes: 18 additions & 2 deletions Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,37 @@
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\TestKernel;
use Doctrine\Bundle\DoctrineBundle\Tests\TestCase;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\ORM\Cache\Region;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

use function get_class;

class CacheCompatibilityPassTest extends TestCase
{
use ExpectDeprecationTrait;

public function testCacheConfigUsingServiceDefinedByApplication(): void
{
(new class () extends TestKernel {
$customRegionClass = get_class($this->createMock(Region::class));

(new class ($customRegionClass) extends TestKernel {
/** @var string */
private $regionClass;

public function __construct(string $regionClass)
{
parent::__construct(false);
$this->regionClass = $regionClass;
}

public function registerContainerConfiguration(LoaderInterface $loader): void
{
parent::registerContainerConfiguration($loader);
$loader->load(static function (ContainerBuilder $containerBuilder): void {
$loader->load(function (ContainerBuilder $containerBuilder): void {
$containerBuilder->loadFromExtension('framework', [
'cache' => [
'pools' => [
Expand All @@ -39,11 +53,13 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
'enabled' => true,
'regions' => [
'lifelong' => ['lifetime' => 0, 'cache_driver' => ['type' => 'pool', 'pool' => 'doctrine.system_cache_pool']],
'entity_cache_region' => ['type' => 'service', 'service' => $this->regionClass],
],
],
],
]
);
$containerBuilder->register($this->regionClass, $this->regionClass);
$containerBuilder->setDefinition(
'custom_cache_service',
(new Definition(DoctrineProvider::class))
Expand Down

0 comments on commit c4998e5

Please sign in to comment.