MappingTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Gedmo\Mapping;
  3. use Doctrine\Common\Util\Debug,
  4. Tree\Fixture\BehavioralCategory,
  5. Gedmo\Mapping\ExtensionMetadataFactory;
  6. /**
  7. * These are mapping extension tests
  8. *
  9. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  10. * @package Gedmo.Mapping
  11. * @link http://www.gediminasm.org
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. class MappingTest extends \PHPUnit_Framework_TestCase
  15. {
  16. const TEST_ENTITY_CATEGORY = "Tree\Fixture\BehavioralCategory";
  17. const TEST_ENTITY_TRANSLATION = "Gedmo\Translatable\Entity\Translation";
  18. private $em;
  19. private $timestampable;
  20. public function setUp()
  21. {
  22. $config = new \Doctrine\ORM\Configuration();
  23. $config->setProxyDir(TESTS_TEMP_DIR);
  24. $config->setProxyNamespace('Gedmo\Mapping\Proxy');
  25. \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
  26. 'Gedmo\\Mapping\\Annotation',
  27. VENDOR_PATH . '/../lib'
  28. );
  29. $this->markTestSkipped('Skipping according to a bug in annotation reader creation.');
  30. $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
  31. $conn = array(
  32. 'driver' => 'pdo_sqlite',
  33. 'memory' => true,
  34. );
  35. //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
  36. $evm = new \Doctrine\Common\EventManager();
  37. $evm->addEventSubscriber(new \Gedmo\Translatable\TranslationListener());
  38. $this->timestampable = new \Gedmo\Timestampable\TimestampableListener();
  39. $evm->addEventSubscriber($this->timestampable);
  40. $evm->addEventSubscriber(new \Gedmo\Sluggable\SluggableListener());
  41. $evm->addEventSubscriber(new \Gedmo\Tree\TreeListener());
  42. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  43. $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
  44. $schemaTool->dropSchema(array());
  45. $schemaTool->createSchema(array(
  46. $this->em->getClassMetadata(self::TEST_ENTITY_CATEGORY),
  47. $this->em->getClassMetadata(self::TEST_ENTITY_TRANSLATION)
  48. ));
  49. }
  50. public function testNoCacheImplementationMapping()
  51. {
  52. $food = new BehavioralCategory();
  53. $food->setTitle('Food');
  54. $this->em->persist($food);
  55. $this->em->flush();
  56. // assertion checks if configuration is read correctly without cache driver
  57. $conf = $this->timestampable->getConfiguration(
  58. $this->em,
  59. self::TEST_ENTITY_CATEGORY
  60. );
  61. $this->assertEquals(0, count($conf));
  62. }
  63. }