ProtectedPropertySupperclassTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Gedmo\Tree;
  3. use Doctrine\Common\Util\Debug;
  4. /**
  5. * These are tests for Timestampable behavior
  6. *
  7. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  8. * @package Gedmo.Tree
  9. * @link http://www.gediminasm.org
  10. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  11. */
  12. class ProtectedPropertySupperclassTest extends \PHPUnit_Framework_TestCase
  13. {
  14. const TEST_ENTITY_CLASS = "Timestampable\Fixture\SupperClassExtension";
  15. const TEST_ENTITY_TRANSLATION = "Gedmo\Translatable\Entity\Translation";
  16. private $em;
  17. public function setUp()
  18. {
  19. $classLoader = new \Doctrine\Common\ClassLoader('Timestampable\Fixture', __DIR__ . '/../');
  20. $classLoader->register();
  21. $config = new \Doctrine\ORM\Configuration();
  22. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  23. $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  24. $config->setProxyDir(__DIR__ . '/Proxy');
  25. $config->setProxyNamespace('Gedmo\Timestampable\Proxies');
  26. $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
  27. $conn = array(
  28. 'driver' => 'pdo_sqlite',
  29. 'memory' => true,
  30. );
  31. //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
  32. $evm = new \Doctrine\Common\EventManager();
  33. $evm->addEventSubscriber(new \Gedmo\Timestampable\TimestampableListener());
  34. $translationListener = new \Gedmo\Translatable\TranslationListener();
  35. $translationListener->setTranslatableLocale('en_us');
  36. $evm->addEventSubscriber($translationListener);
  37. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  38. $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
  39. $schemaTool->dropSchema(array());
  40. $schemaTool->createSchema(array(
  41. $this->em->getClassMetadata(self::TEST_ENTITY_CLASS),
  42. $this->em->getClassMetadata(self::TEST_ENTITY_TRANSLATION)
  43. ));
  44. }
  45. public function testProtectedProperty()
  46. {
  47. $test = new \Timestampable\Fixture\SupperClassExtension;
  48. $test->setName('name');
  49. $test->setTitle('title');
  50. $this->em->persist($test);
  51. $this->em->flush();
  52. $this->em->clear();
  53. $repo = $this->em->getRepository(self::TEST_ENTITY_TRANSLATION);
  54. $translations = $repo->findTranslations($test);
  55. $this->assertEquals(1, count($translations));
  56. $this->assertArrayHasKey('en_us', $translations);
  57. $this->assertEquals(2, count($translations['en_us']));
  58. $this->assertTrue($test->getCreatedAt() !== null);
  59. }
  60. }