MappingEventAdapterTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Gedmo\Mapping;
  3. use Gedmo\Mapping\Mock\EventSubscriberMock;
  4. use Gedmo\Mapping\Mock\EventSubscriberCustomMock;
  5. use Gedmo\Mapping\Event\Adapter\ORM as EventAdapterORM;
  6. use Doctrine\ORM\Event\LifecycleEventArgs;
  7. use Gedmo\Mapping\Mock\Mapping\Event\Adapter\ORM as CustomizedORMAdapter;
  8. class MappingEventAdapterTest extends \PHPUnit_Framework_TestCase
  9. {
  10. public function testCustomizedAdapter()
  11. {
  12. $emMock = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')
  13. ->disableOriginalConstructor()
  14. ->getMock();
  15. $subscriber = new EventSubscriberCustomMock();
  16. $args = new LifecycleEventArgs(new \stdClass(), $emMock);
  17. $adapter = $subscriber->getAdapter($args);
  18. $this->assertTrue($adapter instanceof CustomizedORMAdapter);
  19. }
  20. public function testCorrectAdapter()
  21. {
  22. $emMock = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')
  23. ->disableOriginalConstructor()
  24. ->getMock();
  25. $subscriber = new EventSubscriberMock();
  26. $args = new LifecycleEventArgs(new \stdClass(), $emMock);
  27. $adapter = $subscriber->getAdapter($args);
  28. $this->assertTrue($adapter instanceof EventAdapterORM);
  29. $this->assertTrue($adapter->getObjectManager() === $emMock);
  30. $this->assertTrue($adapter->getObject() instanceof \stdClass);
  31. }
  32. public function testAdapterBehavior()
  33. {
  34. $eventArgsMock = $this->getMockBuilder('Doctrine\\ORM\\Event\\LifecycleEventArgs')
  35. ->disableOriginalConstructor()
  36. ->getMock();
  37. $eventArgsMock->expects($this->once())
  38. ->method('getEntityManager');
  39. $eventArgsMock->expects($this->once())
  40. ->method('getEntity');
  41. $eventAdapter = new EventAdapterORM;
  42. $eventAdapter->setEventArgs($eventArgsMock);
  43. $eventAdapter->getObjectManager();
  44. $eventAdapter->getObject();
  45. }
  46. }