LoggableMappingTest.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. * @package Gedmo.Mapping
  13. * @link http://www.gediminasm.org
  14. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  15. */
  16. class TreeMappingTest extends \PHPUnit_Framework_TestCase
  17. {
  18. const YAML_CATEGORY = 'Mapping\Fixture\Yaml\Category';
  19. private $em;
  20. public function setUp()
  21. {
  22. $config = new \Doctrine\ORM\Configuration();
  23. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  24. $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  25. $config->setProxyDir(TESTS_TEMP_DIR);
  26. $config->setProxyNamespace('Gedmo\Mapping\Proxy');
  27. $chainDriverImpl = new DriverChain;
  28. $chainDriverImpl->addDriver(
  29. new YamlDriver(array(__DIR__ . '/Driver/Yaml')),
  30. 'Mapping\Fixture\Yaml'
  31. );
  32. $config->setMetadataDriverImpl($chainDriverImpl);
  33. $conn = array(
  34. 'driver' => 'pdo_sqlite',
  35. 'memory' => true,
  36. );
  37. //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
  38. $evm = new \Doctrine\Common\EventManager();
  39. $evm->addEventSubscriber(new LoggableListener());
  40. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  41. }
  42. public function testLoggableMapping()
  43. {
  44. $meta = $this->em->getClassMetadata(self::YAML_CATEGORY);
  45. $cacheId = ExtensionMetadataFactory::getCacheId(self::YAML_CATEGORY, 'Gedmo\Loggable');
  46. $config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId);
  47. $this->assertArrayHasKey('loggable', $config);
  48. $this->assertTrue($config['loggable']);
  49. $this->assertArrayHasKey('logEntryClass', $config);
  50. $this->assertEquals('Gedmo\\Loggable\\Entity\\LogEntry', $config['logEntryClass']);
  51. }
  52. }