0

我正在从动作控制器访问选项,该控制器与应用程序配合良好,但是当我尝试对其进行单元测试时遇到了问题:

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;
}

如何正确测试此操作辅助功能?

4

1 回答 1

0

显然,这是 Zend 框架中的一个已知错误:http: //framework.zend.com/issues/browse/ZF-8193?page= com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel

于 2011-04-18T08:18:48.720 回答