开发者

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

开发者 https://www.devze.com 2023-02-25 06:46 出处:网络
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:

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(),
                  开发者_如何学JAVA                       $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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号