LoggableMappingTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Gedmo\Loggable;
  3. use Doctrine\Common\Util\Debug,
  4. Doctrine\ORM\Mapping\Driver\YamlDriver,
  5. Doctrine\ORM\Mapping\Driver\DriverChain,
  6. Mapping\Fixture\Yaml\Category,
  7. Gedmo\Mapping\ExtensionMetadataFactory;
  8. /**
  9. * These are mapping tests for tree extension
  10. *
  11. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  12. * @link http://www.gediminasm.org
  13. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  14. */
  15. class TreeMappingTest extends \PHPUnit_Framework_TestCase
  16. {
  17. const YAML_CATEGORY = 'Mapping\Fixture\Yaml\Category';
  18. private $em;
  19. public function setUp()
  20. {
  21. $config = new \Doctrine\ORM\Configuration();
  22. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  23. $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  24. $config->setProxyDir(TESTS_TEMP_DIR);
  25. $config->setProxyNamespace('Gedmo\Mapping\Proxy');
  26. $chainDriverImpl = new DriverChain;
  27. $chainDriverImpl->addDriver(
  28. new YamlDriver(array(__DIR__ . '/Driver/Yaml')),
  29. 'Mapping\Fixture\Yaml'
  30. );
  31. $config->setMetadataDriverImpl($chainDriverImpl);
  32. $conn = array(
  33. 'driver' => 'pdo_sqlite',
  34. 'memory' => true,
  35. );
  36. //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
  37. $evm = new \Doctrine\Common\EventManager();
  38. $evm->addEventSubscriber(new LoggableListener());
  39. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  40. }
  41. public function testLoggableMapping()
  42. {
  43. $meta = $this->em->getClassMetadata(self::YAML_CATEGORY);
  44. $cacheId = ExtensionMetadataFactory::getCacheId(self::YAML_CATEGORY, 'Gedmo\Loggable');
  45. $config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId);
  46. $this->assertArrayHasKey('loggable', $config);
  47. $this->assertTrue($config['loggable']);
  48. $this->assertArrayHasKey('logEntryClass', $config);
  49. $this->assertEquals('Gedmo\\Loggable\\Entity\\LogEntry', $config['logEntryClass']);
  50. }
  51. }