Zend_Test on Action_Helper accessing $bootstrap->getOptions() error

不想你离开。 提交于 2019-12-13 20:16:16

问题


I am accessing options from an action controller, which is working well with the application, but I've hit a problem when I attempt to UnitTest it:

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

For my tests I followed the setup from ZC at http://www.zendcasts.com/unit-testing-action-helpers/2010/11/ with source available here

I added another test in 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());
}

And I added the following function to /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;
}

How can I properly test this action helper function?


回答1:


Apparently, this is a known bug in the Zend Framework: http://framework.zend.com/issues/browse/ZF-8193?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel



来源:https://stackoverflow.com/questions/5677462/zend-test-on-action-helper-accessing-bootstrap-getoptions-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!