2011-04-15 26 views
0

我從動作控制器,它使用應用程序以及訪問選項,但我已經打了一個問題,當我試圖單元測試它:

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

對於我的測試中我也跟着從ZC設置在http://www.zendcasts.com/unit-testing-action-helpers/2010/11/與可用的源here

我加入測試/庫/ ZC /動作/助手/ 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; 
} 

我怎樣才能正確地測試這個動作的輔助功能?

回答