Zend_Test on Action_Helper accessing $bootstrap->g

2019-08-27 19:18发布

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条回答
登录 后发表回答