TimestampableMappingTest.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * @package Gedmo.Mapping
  13. * @link http://www.gediminasm.org
  14. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  15. */
  16. class TimestampableMappingTest extends \PHPUnit_Framework_TestCase
  17. {
  18. const TEST_YAML_ENTITY_CLASS = '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 TimestampableListener());
  40. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  41. }
  42. public function testYamlMapping()
  43. {
  44. $meta = $this->em->getClassMetadata(self::TEST_YAML_ENTITY_CLASS);
  45. $cacheId = ExtensionMetadataFactory::getCacheId(
  46. self::TEST_YAML_ENTITY_CLASS,
  47. 'Gedmo\Timestampable'
  48. );
  49. $config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId);
  50. $this->assertArrayHasKey('create', $config);
  51. $this->assertEquals('created', $config['create'][0]);
  52. $this->assertArrayHasKey('update', $config);
  53. $this->assertEquals('updated', $config['update'][0]);
  54. $this->assertArrayHasKey('change', $config);
  55. $onChange = $config['change'][0];
  56. $this->assertEquals('changed', $onChange['field']);
  57. $this->assertEquals('title', $onChange['trackedField']);
  58. $this->assertEquals('Test', $onChange['value']);
  59. }
  60. }