在下面的设置中,有
控制器动作(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用于example above。
答案 0 :(得分:1)
尝试:
$this->render('index/instead-of-hello.phtml');
这是文档中的解释:
$this->renderScript()
使用此方法时,ViewRenderer不会自动确定 脚本名称,而是直接传递$ script参数 直接到视图对象的render()方法。