问题
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