NoInterfaceTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. $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. $timestampableListener = new TimestampableListener();
  34. $evm->addEventSubscriber($timestampableListener);
  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. ));
  41. }
  42. public function testTimestampableNoInterface()
  43. {
  44. $test = new WithoutInterface();
  45. $test->setTitle('Test');
  46. $date = new \DateTime('now');
  47. $this->em->persist($test);
  48. $this->em->flush();
  49. $this->em->clear();
  50. $test = $this->em->getRepository(self::TEST_ENTITY_CLASS)->findOneByTitle('Test');
  51. $this->assertEquals(
  52. $date->format('Y-m-d 00:00:00'),
  53. $test->getCreated()->format('Y-m-d H:i:s')
  54. );
  55. $this->assertEquals(
  56. $date->format('Y-m-d H:i:s'),
  57. $test->getUpdated()->format('Y-m-d H:i:s')
  58. );
  59. }
  60. }