TraitUsageTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Gedmo\Blameable;
  3. use Doctrine\Common\EventManager;
  4. use Tool\BaseTestCaseORM;
  5. use Blameable\Fixture\Entity\UsingTrait;
  6. /**
  7. * These are tests for Blameable 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 = "Blameable\\Fixture\\Entity\\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. $listener = new BlameableListener;
  23. $listener->setUserValue('testuser');
  24. $evm = new EventManager;
  25. $evm->addEventSubscriber($listener);
  26. $this->getMockSqliteEntityManager($evm);
  27. }
  28. /**
  29. * @test
  30. */
  31. function shouldTimestampUsingTrait()
  32. {
  33. $sport = new UsingTrait;
  34. $sport->setTitle('Sport');
  35. $this->em->persist($sport);
  36. $this->em->flush();
  37. $this->assertNotNull($sport->getCreatedBy());
  38. $this->assertNotNull($sport->getUpdatedBy());
  39. }
  40. /**
  41. * @test
  42. */
  43. function traitMethodthShouldReturnObject()
  44. {
  45. $sport = new UsingTrait;
  46. $this->assertInstanceOf(self::TARGET, $sport->setCreatedBy('myuser'));
  47. $this->assertInstanceOf(self::TARGET, $sport->setUpdatedBy('myuser'));
  48. }
  49. protected function getUsedEntityFixtures()
  50. {
  51. return array(
  52. self::TARGET
  53. );
  54. }
  55. }