public function testLiveAction() { // MOCKS $mockPage = $this->getMock('Networking\\InitCmsBundle\\Model\\Page'); $mockPage->expects($this->once())->method('getVisibility')->will($this->returnValue(PageInterface::VISIBILITY_PUBLIC)); $mockPage->expects($this->once())->method('isActive')->will($this->returnValue(true)); $mockSnapshot = $this->getMockBuilder('Networking\\InitCmsBundle\\Entity\\PageSnapshot')->disableOriginalConstructor()->getMock(); $mockHelper = $this->getMockBuilder('Networking\\InitCmsBundle\\Helper\\PageHelper')->disableOriginalConstructor()->getMock(); $mockHelper->expects($this->once())->method('unserializePageSnapshotData')->will($this->returnValue($mockPage)); //security context $mockSecurityContext = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\SecurityContext')->disableOriginalConstructor()->getMock(); $mockSecurityContext->expects($this->any())->method('isGranted')->with('ROLE_USER')->will($this->returnValue(true)); //templating $mockTemplating = $this->getMockBuilder('\\Symfony\\Bundle\\TwigBundle\\Debug\\TimedTwigEngine')->disableOriginalConstructor()->getMock(); $mockResponse = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Response')->getMock(); $mockTemplating->expects($this->once())->method('renderResponse')->will($this->returnValue($mockResponse)); //request $mockRequest = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock(); $mockRequest->expects($this->at(0))->method('get')->with('_content')->will($this->returnValue($mockSnapshot)); $mockRequest->expects($this->at(1))->method('get')->with('_template'); //Container $mockContainer = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container')->disableOriginalConstructor()->getMock(); $mockContainer->expects($this->at(0))->method('get')->with('networking_init_cms.helper.page_helper')->will($this->returnValue($mockHelper)); $mockContainer->expects($this->at(1))->method('get')->with('security.context')->will($this->returnValue($mockSecurityContext)); $mockContainer->expects($this->at(2))->method('get')->with('templating')->will($this->returnValue($mockTemplating)); // controller $controller = new FrontendPageController(); $controller->setContainer($mockContainer); $response = $controller->liveAction($mockRequest); $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $response, 'response object returned'); }