我正在从动作控制器访问选项,该控制器与应用程序配合良好,但是当我尝试对其进行单元测试时遇到了问题:
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
对于我的测试,我按照 ZC 的设置在此处http://www.zendcasts.com/unit-testing-action-helpers/2010/11/
提供了源代码
我在 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;
}
如何正确测试此操作辅助功能?