0

アクションコントローラーからオプションにアクセスしています。これはアプリケーションでうまく機能していますが、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;
}

このアクションヘルパー関数を適切にテストするにはどうすればよいですか?

4

1 に答える 1

0

どうやら、これは Zend Framework の既知のバグです: http://framework.zend.com/issues/browse/ZF-8193?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel

于 2011-04-18T08:18:48.720 に答える