TraitUsageTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Gedmo\Timestampable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Timestampable\Fixture\UsingTrait;
  6. /**
  7. * These are tests for Timestampable behavior
  8. *
  9. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  10. * @link http://www.gediminasm.org
  11. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  12. */
  13. class TraitUsageTest extends BaseTestCaseORM
  14. {
  15. const TARGET = "Timestampable\\Fixture\\UsingTrait";
  16. protected function setUp()
  17. {
  18. parent::setUp();
  19. if (version_compare(PHP_VERSION, '5.4.0') < 0) {
  20. $this->markTestSkipped('PHP >= 5.4 version required for this test.');
  21. }
  22. $evm = new EventManager;
  23. $evm->addEventSubscriber(new TimestampableListener);
  24. $this->getMockSqliteEntityManager($evm);
  25. }
  26. /**
  27. * @test
  28. */
  29. function shouldTimestampUsingTrait()
  30. {
  31. $sport = new UsingTrait;
  32. $sport->setTitle('Sport');
  33. $this->em->persist($sport);
  34. $this->em->flush();
  35. $this->assertNotNull($sport->getCreatedAt());
  36. $this->assertNotNull($sport->getUpdatedAt());
  37. }
  38. /**
  39. * @test
  40. */
  41. function traitMethodthShouldReturnObject()
  42. {
  43. $sport = new UsingTrait;
  44. $this->assertInstanceOf('Timestampable\Fixture\UsingTrait', $sport->setCreatedAt(new \DateTime()));
  45. $this->assertInstanceOf('Timestampable\Fixture\UsingTrait', $sport->setUpdatedAt(new \DateTime()));
  46. }
  47. protected function getUsedEntityFixtures()
  48. {
  49. return array(
  50. self::TARGET
  51. );
  52. }
  53. }