在下面的设置中,有
一个控制器操作 (index/hello) 呈现不同于默认的视图脚本,
index/instead-of-hello.phtml
而不是index/hello.phtml
public function helloAction()
{
$this->renderScript('index/instead-of-hello.phtml');
}
我想对动作实际呈现进行单元测试 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());
}
此测试失败,因为renderer->getViewScript()
返回的是默认渲染的脚本,而不是实际渲染的脚本。
1) IndexControllerTest::testHelloAction
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-index/instead-of-hello.phtml
+index/hello.phtml
我怎样才能成功地测试脚本index/instead-of-hello.phtml
是否真的被渲染了?
上面的例子使用了 Zend Framework 1.12 。