Networking\InitCmsBundle\Tests\Entity\PageListenerTest::testPostUpdate_WithPage PHP Метод

testPostUpdate_WithPage() публичный Метод

postUpdate with Page and no children
    public function testPostUpdate_WithPage()
    {
        $container = $this->getMock('\\Symfony\\Component\\DependencyInjection\\Container');
        $pageListener = new PageListener(new \Symfony\Component\HttpFoundation\Session\Session(), $container);
        // contentRoute
        $contentRoute = $this->getMock('\\Networking\\InitCmsBundle\\Model\\ContentRoute', array('setPath'));
        $contentRoute->expects($this->once())->method('setPath')->with($this->equalTo('/'));
        // entity
        $entity = $this->getMock('\\Networking\\InitCmsBundle\\Model\\Page');
        $entity->expects($this->once())->method('getContentRoute')->will($this->returnValue($contentRoute));
        $entity->expects($this->exactly(1))->method('getAllChildren')->will($this->returnValue($this->getMockChildren(0)));
        // 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->exactly(1))->method('persist');
        //UnitOfWork tests
        $uow->expects($this->once())->method('getScheduledEntityUpdates')->will($this->returnValue(array($entity)));
        $uow->expects($this->exactly(1))->method('computeChangeSet');
        $args = $this->getMockBuilder('\\Doctrine\\ORM\\Event\\OnFlushEventArgs')->disableOriginalConstructor()->getMock();
        // args methods:
        // getObjectManager
        $args->expects($this->once())->method('getEntityManager')->will($this->returnValue($em));
        $pageListener->onFlush($args);
    }