TimestampableMappingTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Gedmo\Timestampable;
  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 timestampable 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 TimestampableMappingTest extends \PHPUnit_Framework_TestCase
  16. {
  17. const TEST_YAML_ENTITY_CLASS = '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 TimestampableListener());
  39. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  40. }
  41. public function testYamlMapping()
  42. {
  43. $meta = $this->em->getClassMetadata(self::TEST_YAML_ENTITY_CLASS);
  44. $cacheId = ExtensionMetadataFactory::getCacheId(
  45. self::TEST_YAML_ENTITY_CLASS,
  46. 'Gedmo\Timestampable'
  47. );
  48. $config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId);
  49. $this->assertArrayHasKey('create', $config);
  50. $this->assertEquals('created', $config['create'][0]);
  51. $this->assertArrayHasKey('update', $config);
  52. $this->assertEquals('updated', $config['update'][0]);
  53. $this->assertArrayHasKey('change', $config);
  54. $onChange = $config['change'][0];
  55. $this->assertEquals('changed', $onChange['field']);
  56. $this->assertEquals('title', $onChange['trackedField']);
  57. $this->assertEquals('Test', $onChange['value']);
  58. }
  59. }