CompatibilityMappingTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Gedmo\Mapping;
  3. use Mapping\Fixture\Compatibility\Article;
  4. use Doctrine\Common\Annotations\AnnotationReader;
  5. use Doctrine\Common\Annotations\CachedReader;
  6. use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
  7. use Doctrine\Common\Cache\ArrayCache;
  8. /**
  9. * These are mapping extension tests
  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 CompatibilityMappingTest extends \PHPUnit_Framework_TestCase
  17. {
  18. const ARTICLE = "Mapping\Fixture\Compatibility\Article";
  19. private $em;
  20. private $timestampable;
  21. public function setUp()
  22. {
  23. if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0RC4-DEV', '>=')) {
  24. $this->markTestSkipped('Doctrine common is 2.1.0RC4-DEV version, skipping.');
  25. } else if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
  26. $reader = new AnnotationReader();
  27. $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
  28. $reader->setIgnoreNotImportedAnnotations(true);
  29. $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
  30. $reader->setEnableParsePhpImports(false);
  31. $reader->setAutoloadAnnotations(true);
  32. $reader = new CachedReader(
  33. new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()
  34. );
  35. } else {
  36. $reader = new AnnotationReader();
  37. $reader->setAutoloadAnnotations(true);
  38. $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
  39. $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
  40. }
  41. $config = new \Doctrine\ORM\Configuration();
  42. $config->setProxyDir(TESTS_TEMP_DIR);
  43. $config->setProxyNamespace('Gedmo\Mapping\Proxy');
  44. $config->setMetadataDriverImpl(new AnnotationDriver($reader));
  45. $conn = array(
  46. 'driver' => 'pdo_sqlite',
  47. 'memory' => true,
  48. );
  49. //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
  50. $evm = new \Doctrine\Common\EventManager();
  51. $this->timestampable = new \Gedmo\Timestampable\TimestampableListener();
  52. $evm->addEventSubscriber($this->timestampable);
  53. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  54. $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
  55. $schemaTool->dropSchema(array());
  56. $schemaTool->createSchema(array(
  57. $this->em->getClassMetadata(self::ARTICLE)
  58. ));
  59. }
  60. public function testNoCacheImplementationMapping()
  61. {
  62. $test = new Article;
  63. $test->setTitle('test');
  64. $this->em->persist($test);
  65. $this->em->flush();
  66. // assertion checks if configuration is read correctly without cache driver
  67. $conf = $this->timestampable->getConfiguration(
  68. $this->em,
  69. self::ARTICLE
  70. );
  71. $this->assertArrayHasKey('create', $conf);
  72. $this->assertArrayHasKey('update', $conf);
  73. }
  74. }