ProtectedPropertySupperclassTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. $config = new \Doctrine\ORM\Configuration();
  20. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  21. $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  22. $config->setProxyDir(__DIR__ . '/Proxy');
  23. $config->setProxyNamespace('Gedmo\Timestampable\Proxies');
  24. $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
  25. $conn = array(
  26. 'driver' => 'pdo_sqlite',
  27. 'memory' => true,
  28. );
  29. //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
  30. $evm = new \Doctrine\Common\EventManager();
  31. $evm->addEventSubscriber(new \Gedmo\Timestampable\TimestampableListener());
  32. $translationListener = new \Gedmo\Translatable\TranslationListener();
  33. $translationListener->setTranslatableLocale('en_us');
  34. $evm->addEventSubscriber($translationListener);
  35. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  36. $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
  37. $schemaTool->dropSchema(array());
  38. $schemaTool->createSchema(array(
  39. $this->em->getClassMetadata(self::TEST_ENTITY_CLASS),
  40. $this->em->getClassMetadata(self::TEST_ENTITY_TRANSLATION)
  41. ));
  42. }
  43. public function testProtectedProperty()
  44. {
  45. $test = new \Timestampable\Fixture\SupperClassExtension;
  46. $test->setName('name');
  47. $test->setTitle('title');
  48. $this->em->persist($test);
  49. $this->em->flush();
  50. $this->em->clear();
  51. $repo = $this->em->getRepository(self::TEST_ENTITY_TRANSLATION);
  52. $translations = $repo->findTranslations($test);
  53. $this->assertEquals(1, count($translations));
  54. $this->assertArrayHasKey('en_us', $translations);
  55. $this->assertEquals(2, count($translations['en_us']));
  56. $this->assertTrue($test->getCreatedAt() !== null);
  57. }
  58. }