NoInterfaceTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Gedmo\Timestampable;
  3. use Doctrine\Common\Util\Debug,
  4. Timestampable\Fixture\WithoutInterface;
  5. /**
  6. * These are tests for Timestampable behavior
  7. *
  8. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  9. * @package Gedmo.Timestampable
  10. * @link http://www.gediminasm.org
  11. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  12. */
  13. class NoInterfaceTest extends \PHPUnit_Framework_TestCase
  14. {
  15. const TEST_ENTITY_CLASS = "Timestampable\Fixture\WithoutInterface";
  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. $timestampableListener = new TimestampableListener();
  32. $evm->addEventSubscriber($timestampableListener);
  33. $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
  34. $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
  35. $schemaTool->dropSchema(array());
  36. $schemaTool->createSchema(array(
  37. $this->em->getClassMetadata(self::TEST_ENTITY_CLASS)
  38. ));
  39. }
  40. public function testTimestampableNoInterface()
  41. {
  42. $test = new WithoutInterface();
  43. $test->setTitle('Test');
  44. $date = new \DateTime('now');
  45. $this->em->persist($test);
  46. $this->em->flush();
  47. $this->em->clear();
  48. $test = $this->em->getRepository(self::TEST_ENTITY_CLASS)->findOneByTitle('Test');
  49. $this->assertEquals(
  50. $date->format('Y-m-d 00:00:00'),
  51. $test->getCreated()->format('Y-m-d H:i:s')
  52. );
  53. $this->assertEquals(
  54. $date->format('Y-m-d H:i:s'),
  55. $test->getUpdated()->format('Y-m-d H:i:s')
  56. );
  57. }
  58. }