-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use own cache to store configuration
- Loading branch information
Showing
11 changed files
with
191 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,31 +11,33 @@ | |
|
||
namespace Gedmo\Tests\Mapping; | ||
|
||
use Doctrine\Common\EventManager; | ||
use Doctrine\ORM\Mapping\Driver\YamlDriver; | ||
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; | ||
use Gedmo\Loggable\Entity\LogEntry; | ||
use Gedmo\Loggable\LoggableListener; | ||
use Gedmo\Mapping\ExtensionMetadataFactory; | ||
use Gedmo\Tests\Mapping\Fixture\Yaml\Category; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
|
||
/** | ||
* These are mapping tests for tree extension | ||
* | ||
* @author Gediminas Morkevicius <[email protected]> | ||
*/ | ||
final class LoggableMappingTest extends \PHPUnit\Framework\TestCase | ||
final class LoggableORMMappingTest extends ORMMappingTestCase | ||
{ | ||
public const YAML_CATEGORY = Category::class; | ||
|
||
/** | ||
* @var \Doctrine\ORM\EntityManager | ||
*/ | ||
private $em; | ||
|
||
protected function setUp(): void | ||
{ | ||
$config = new \Doctrine\ORM\Configuration(); | ||
$config->setMetadataCache(new ArrayAdapter()); | ||
$config->setQueryCache(new ArrayAdapter()); | ||
$config->setProxyDir(TESTS_TEMP_DIR); | ||
$config->setProxyNamespace('Gedmo\Mapping\Proxy'); | ||
parent::setUp(); | ||
|
||
$config = $this->getBasicConfiguration(); | ||
$chainDriverImpl = new MappingDriverChain(); | ||
$chainDriverImpl->addDriver( | ||
new YamlDriver([__DIR__.'/Driver/Yaml']), | ||
|
@@ -48,18 +50,18 @@ protected function setUp(): void | |
'memory' => true, | ||
]; | ||
|
||
//$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); | ||
|
||
$evm = new \Doctrine\Common\EventManager(); | ||
$evm->addEventSubscriber(new LoggableListener()); | ||
$evm = new EventManager(); | ||
$loggableListener = new LoggableListener(); | ||
$loggableListener->setCacheItemPool($this->cache); | ||
$evm->addEventSubscriber($loggableListener); | ||
$this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); | ||
} | ||
|
||
public function testLoggableMapping(): void | ||
{ | ||
$meta = $this->em->getClassMetadata(self::YAML_CATEGORY); | ||
$cacheId = ExtensionMetadataFactory::getCacheId(self::YAML_CATEGORY, 'Gedmo\Loggable'); | ||
$config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId); | ||
$config = $this->cache->getItem($cacheId)->get(); | ||
|
||
static::assertArrayHasKey('loggable', $config); | ||
static::assertTrue($config['loggable']); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Doctrine Behavioral Extensions package. | ||
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gedmo\Tests\Mapping; | ||
|
||
use Doctrine\ORM\Configuration; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
|
||
abstract class ORMMappingTestCase extends TestCase | ||
{ | ||
/** | ||
* @var CacheItemPoolInterface | ||
*/ | ||
protected $cache; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->cache = new ArrayAdapter(); | ||
} | ||
|
||
final protected function getBasicConfiguration(): Configuration | ||
{ | ||
$config = new Configuration(); | ||
$config->setMetadataCache(new ArrayAdapter()); | ||
$config->setQueryCache(new ArrayAdapter()); | ||
$config->setProxyDir(TESTS_TEMP_DIR); | ||
$config->setProxyNamespace('Gedmo\Mapping\Proxy'); | ||
|
||
return $config; | ||
} | ||
} |
Oops, something went wrong.