MappingTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * @link http://www.gediminasm.org
  11. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  12. */
  13. class MappingTest extends \PHPUnit_Framework_TestCase
  14. {
  15. const TEST_ENTITY_CATEGORY = "Tree\Fixture\BehavioralCategory";
  16. const TEST_ENTITY_TRANSLATION = "Gedmo\Translatable\Entity\Translation";
  17. private $em;
  18. private $timestampable;
  19. public function setUp()
  20. {
  21. $config = new \Doctrine\ORM\Configuration();
  22. $config->setProxyDir(TESTS_TEMP_DIR);
  23. $config->setProxyNamespace('Gedmo\Mapping\Proxy');
  24. //$this->markTestSkipped('Skipping according to a bug in annotation reader creation.');
  25. $config->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($_ENV['annotation_reader']));
  26. $conn = array(
  27. 'driver' => 'pdo_sqlite',
  28. 'memory' => true,
  29. );
  30. $evm = new \Doctrine\Common\EventManager();
  31. $evm->addEventSubscriber(new \Gedmo\Translatable\TranslatableListener());
  32. $this->timestampable = new \Gedmo\Timestampable\TimestampableListener();
  33. $evm->addEventSubscriber($this->timestampable);
  34. $evm->addEventSubscriber(new \Gedmo\Sluggable\SluggableListener());
  35. $evm->addEventSubscriber(new \Gedmo\Tree\TreeListener());
  36. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  37. $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
  38. $schemaTool->dropSchema(array());
  39. $schemaTool->createSchema(array(
  40. $this->em->getClassMetadata(self::TEST_ENTITY_CATEGORY),
  41. $this->em->getClassMetadata(self::TEST_ENTITY_TRANSLATION)
  42. ));
  43. }
  44. public function testNoCacheImplementationMapping()
  45. {
  46. $food = new BehavioralCategory();
  47. $food->setTitle('Food');
  48. $this->em->persist($food);
  49. $this->em->flush();
  50. // assertion checks if configuration is read correctly without cache driver
  51. $conf = $this->timestampable->getConfiguration(
  52. $this->em,
  53. self::TEST_ENTITY_CATEGORY
  54. );
  55. $this->assertCount(0, $conf);
  56. }
  57. }