我正在从动作控制器访问选项,它与应用程序运行良好,但是当我尝试使用UnitTest时遇到了问题:
PHP Fatal error: Call to a member function getOptions() on a non-object in /home/zendtest/library/ZC/Action/Helper/Signup.php on line 43
对于我的测试,我在http://www.zendcasts.com/unit-testing-action-helpers/2010/11/
跟踪了ZC的设置,可用来源here
我在tests / library / ZC / Action / Helper / SignupTest.php中添加了另一个测试:
public function testMyTest()
{
$helper = new ZC_Action_Helper_Signup();
$this->dispatch('/');
$controller = new IndexController($this->getRequest(),
$this->getResponse(), array());
$helper->setActionController($controller);
$this->assertType('Zend_View',$helper->getConfig());
}
我在/library/ZC/Action/Helper/Signup.php中添加了以下功能:
protected $_config;
public function getConfig()
{
if (null == $this->_config) {
$action = $this->getActionController();
$bootstrap = $action->getInvokeArg('bootstrap');
$config = $bootstrap->getOptions();
$this->_config = new Zend_Config($config);
}
return $this->_config;
}
如何正确测试此动作助手功能?
答案 0 :(得分:0)