twig = $this->getMockBuilder('TwigWrapper') ->disableOriginalConstructor() ->getMock(); $this->testObj = new Default404Page($this->twig); } public function tearDown() { } public function testDisplayDisplaysThe404Template() { $expected = TestUtils::getRandomString(20); $this->twig->expects($this->once()) ->method('render') ->with('404page.html', array()) ->willReturn($expected); // train mock $actual = $this->testObj->display(); $this->assertEquals($expected, $actual); } }