Skip to content

Commit

Permalink
Fix Second level cache config
Browse files Browse the repository at this point in the history
  • Loading branch information
FVesely authored and mabar committed Feb 7, 2020
1 parent 4895b56 commit b2fa8b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DI/OrmCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getConfigSchema(): Schema
'hydrationCache' => $this->getServiceSchema(),
'metadataCache' => $this->getServiceSchema(),
'resultCache' => $this->getServiceSchema(),
'secondLevelCache' => Expect::array()->default(null),
'secondLevelCache' => $this->getServiceSchema(),
]);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/cases/Unit/DI/OrmCacheExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\PhpFileCache;
use Doctrine\Common\Cache\VoidCache;
use Doctrine\ORM\Cache\CacheConfiguration;
use Nette\DI\Compiler;
use Nette\DI\Container;
use Nette\DI\ContainerLoader;
Expand All @@ -17,6 +18,7 @@
use Nettrine\ORM\DI\OrmCacheExtension;
use Nettrine\ORM\DI\OrmExtension;
use Nettrine\ORM\EntityManagerDecorator;
use Tests\Fixtures\DummyCacheConfigurationFactory;
use Tests\Toolkit\TestCase;

final class OrmCacheExtensionTest extends TestCase
Expand Down Expand Up @@ -68,6 +70,7 @@ public function testProvidedCacheDrivers(): void
'hydrationCache' => VoidCache::class,
'metadataCache' => null,
'queryCache' => ApcuCache::class,
'secondLevelCache' => [DummyCacheConfigurationFactory::class, 'create'],
//'resultCache' => null,
],
'parameters' => [
Expand All @@ -87,6 +90,7 @@ public function testProvidedCacheDrivers(): void
$this->assertInstanceOf(ArrayCache::class, $em->getConfiguration()->getMetadataCacheImpl());
$this->assertInstanceOf(ApcuCache::class, $em->getConfiguration()->getQueryCacheImpl());
$this->assertInstanceOf(ArrayCache::class, $em->getConfiguration()->getResultCacheImpl());
$this->assertInstanceOf(CacheConfiguration::class, $em->getConfiguration()->getSecondLevelCacheConfiguration());
}

public function testNoCacheDriver(): void
Expand Down
25 changes: 25 additions & 0 deletions tests/fixtures/DummyCacheConfigurationFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1);

namespace Tests\Fixtures;

use Doctrine\Common\Cache\ArrayCache;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Cache\DefaultCacheFactory;
use Doctrine\ORM\Cache\RegionsConfiguration;

final class DummyCacheConfigurationFactory
{

public static function create(): CacheConfiguration
{
$regionsConfiguration = new RegionsConfiguration();
$cache = new ArrayCache();
$cacheFactory = new DefaultCacheFactory($regionsConfiguration, $cache);

$cacheConfiguration = new CacheConfiguration();
$cacheConfiguration->setCacheFactory($cacheFactory);

return $cacheConfiguration;
}

}

0 comments on commit b2fa8b9

Please sign in to comment.