MappingTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  24. //$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  25. $config->setProxyDir(__DIR__ . '/Proxy');
  26. $config->setProxyNamespace('Gedmo\Mapping\Proxy');
  27. $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
  28. $conn = array(
  29. 'driver' => 'pdo_sqlite',
  30. 'memory' => true,
  31. );
  32. //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
  33. $evm = new \Doctrine\Common\EventManager();
  34. $evm->addEventSubscriber(new \Gedmo\Translatable\TranslationListener());
  35. $this->timestampable = new \Gedmo\Timestampable\TimestampableListener();
  36. $evm->addEventSubscriber($this->timestampable);
  37. $evm->addEventSubscriber(new \Gedmo\Sluggable\SluggableListener());
  38. $evm->addEventSubscriber(new \Gedmo\Tree\TreeListener());
  39. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  40. $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
  41. $schemaTool->dropSchema(array());
  42. $schemaTool->createSchema(array(
  43. $this->em->getClassMetadata(self::TEST_ENTITY_CATEGORY),
  44. $this->em->getClassMetadata(self::TEST_ENTITY_TRANSLATION)
  45. ));
  46. }
  47. public function testNoCacheImplementationMapping()
  48. {
  49. $food = new BehavioralCategory();
  50. $food->setTitle('Food');
  51. $this->em->persist($food);
  52. $this->em->flush();
  53. // assertion checks if configuration is read correctly without cache driver
  54. $conf = $this->timestampable->getConfiguration(
  55. $this->em,
  56. self::TEST_ENTITY_CATEGORY
  57. );
  58. $this->assertEquals(0, count($conf));
  59. }
  60. }