アクションコントローラーからオプションにアクセスしています。これはアプリケーションでうまく機能していますが、UnitTest しようとすると問題が発生しました:
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
私のテストでは、ここhttp://www.zendcasts.com/unit-testing-action-helpers/2010/11/
でソースを入手できるZCのセットアップに従いました
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;
}
このアクションヘルパー関数を適切にテストするにはどうすればよいですか?