postPersist() 공개 메소드

public postPersist ( Doctrine\Common\Persistence\Event\LifecycleEventArgs $args ) : mixed | void
$args Doctrine\Common\Persistence\Event\LifecycleEventArgs
리턴 mixed | void
예제 #1
0
 /**
  * postPersist with Page
  */
 public function testPostPersist_WithPage()
 {
     $container = $this->getMock('\\Symfony\\Component\\DependencyInjection\\Container');
     $pageListener = new PageListener(new \Symfony\Component\HttpFoundation\Session\Session(), $container);
     $contentRoute = $this->getMock('\\Networking\\InitCmsBundle\\Model\\ContentRoute', array('setPath', 'setObjectId'));
     $contentRoute->expects($this->once())->method('setPath')->with($this->equalTo('/some/random-pi/path'));
     $contentRoute->expects($this->once())->method('setObjectId')->with($this->equalTo(108));
     // entity
     $entity = $this->getMock('\\Networking\\InitCmsBundle\\Model\\Page');
     $entity->expects($this->once())->method('getId')->will($this->returnValue(108));
     $entity->expects($this->once())->method('getPath')->will($this->returnValue('/some-25465/random-pi/path-4'));
     $entity->expects($this->once())->method('getContentRoute')->will($this->returnValue($contentRoute));
     // em
     $em = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $uow = $this->getMockBuilder('\\Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
     $em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($uow));
     $classMetaData = $this->getMockBuilder('\\Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $em->expects($this->once())->method('getClassMetadata')->will($this->returnValue($classMetaData));
     $em->expects($this->once())->method('persist');
     $args = $this->getMockBuilder('\\Doctrine\\ORM\\Event\\LifecycleEventArgs')->disableOriginalConstructor()->getMock();
     // args methods:
     // getEntity
     $args->expects($this->once())->method('getEntity')->will($this->returnValue($entity));
     // getEntityManager
     $args->expects($this->once())->method('getEntityManager')->will($this->returnValue($em));
     $pageListener->postPersist($args);
 }