In the setup below, there is
a controller action (index/hello) that renders a view script different than the default
index/instead-of-hello.phtml instead of index/hello.phtml
public function helloAction()
{
$this->renderScript('index/instead-of-hello.phtml');
}
I would like to unit test that the action actually renders index/instead-of-hello.phtml
public function testHelloAction()
{
$params = array('action' => 'hello', 'controller' => 'Index', 'module' => 'default');
$urlParams = $this->urlizeOptions($params);
$url = $this->url($urlParams);
$this->dispatch($url);
$renderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
$this->assertEquals('index/instead-of-hello.phtml', $renderer->getViewScript());
}
This test fails since the renderer->getViewScript() returns the script that would be rendered by default and not the one that was actually rendered.
1) IndexControllerTest::testHelloAction
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-index/instead-of-hello.phtml
+index/hello.phtml
How could I successfully test that the script index/instead-of-hello.phtml was actually rendered?
Zend Framework 1.12 is used on the example above.
try:
here is the explanation from Documentation: