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: // getObject $args->expects($this->once())->method('getObject')->will($this->returnValue($entity)); // getObjectManager $args->expects($this->once())->method('getObjectManager')->will($this->returnValue($em)); $pageListener->postPersist($args); }