TraitUsageTest.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. * @package Gedmo.Timestampable
  11. * @link http://www.gediminasm.org
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. class TraitUsageTest extends BaseTestCaseORM
  15. {
  16. const TARGET = "Timestampable\\Fixture\\UsingTrait";
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. if (version_compare(PHP_VERSION, '5.4.0') < 0) {
  21. $this->markTestSkipped('PHP >= 5.4 version required for this test.');
  22. }
  23. $evm = new EventManager;
  24. $evm->addEventSubscriber(new TimestampableListener);
  25. $this->getMockSqliteEntityManager($evm);
  26. }
  27. /**
  28. * @test
  29. */
  30. function shouldTimestampUsingTrait()
  31. {
  32. $sport = new UsingTrait;
  33. $sport->setTitle('Sport');
  34. $this->em->persist($sport);
  35. $this->em->flush();
  36. $this->assertNotNull($sport->getCreatedAt());
  37. $this->assertNotNull($sport->getUpdatedAt());
  38. }
  39. /**
  40. * @test
  41. */
  42. function traitMethodthShouldReturnObject()
  43. {
  44. $sport = new UsingTrait;
  45. $this->assertInstanceOf('Timestampable\Fixture\UsingTrait', $sport->setCreatedAt(new \DateTime()));
  46. $this->assertInstanceOf('Timestampable\Fixture\UsingTrait', $sport->setUpdatedAt(new \DateTime()));
  47. }
  48. protected function getUsedEntityFixtures()
  49. {
  50. return array(
  51. self::TARGET
  52. );
  53. }
  54. }