1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace Gedmo\Timestampable;
- use Doctrine\Common\Util\Debug,
- Doctrine\ORM\Mapping\Driver\YamlDriver,
- Doctrine\ORM\Mapping\Driver\DriverChain,
- Mapping\Fixture\Yaml\Category,
- Gedmo\Mapping\ExtensionMetadataFactory;
- /**
- * These are mapping tests for timestampable extension
- *
- * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
- * @link http://www.gediminasm.org
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
- class TimestampableMappingTest extends \PHPUnit_Framework_TestCase
- {
- const TEST_YAML_ENTITY_CLASS = 'Mapping\Fixture\Yaml\Category';
- private $em;
- public function setUp()
- {
- $config = new \Doctrine\ORM\Configuration();
- $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
- $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
- $config->setProxyDir(TESTS_TEMP_DIR);
- $config->setProxyNamespace('Gedmo\Mapping\Proxy');
- $chainDriverImpl = new DriverChain;
- $chainDriverImpl->addDriver(
- new YamlDriver(array(__DIR__ . '/Driver/Yaml')),
- 'Mapping\Fixture\Yaml'
- );
- $config->setMetadataDriverImpl($chainDriverImpl);
- $conn = array(
- 'driver' => 'pdo_sqlite',
- 'memory' => true,
- );
- //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
- $evm = new \Doctrine\Common\EventManager();
- $evm->addEventSubscriber(new TimestampableListener());
- $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
- }
- public function testYamlMapping()
- {
- $meta = $this->em->getClassMetadata(self::TEST_YAML_ENTITY_CLASS);
- $cacheId = ExtensionMetadataFactory::getCacheId(
- self::TEST_YAML_ENTITY_CLASS,
- 'Gedmo\Timestampable'
- );
- $config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId);
- $this->assertArrayHasKey('create', $config);
- $this->assertEquals('created', $config['create'][0]);
- $this->assertArrayHasKey('update', $config);
- $this->assertEquals('updated', $config['update'][0]);
- $this->assertArrayHasKey('change', $config);
- $onChange = $config['change'][0];
- $this->assertEquals('changed', $onChange['field']);
- $this->assertEquals('title', $onChange['trackedField']);
- $this->assertEquals('Test', $onChange['value']);
- }
- }
|