2012-07-13 85 views
0

我正在使用Zend_Test。下面是我的測試/ bootstrap.php中的文件:引導問題zend_test/phpunit

// Define path to application directory 
defined('APPLICATION_PATH') 
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); 

// Define application environment 
defined('APPLICATION_ENV') 
    || define('APPLICATION_ENV', 'testing'); 

// Ensure library/ is on include_path 
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'), 
    get_include_path(), 
))); 

require_once 'Zend/Loader/Autoloader.php'; 
$autoloader = Zend_Loader_Autoloader::getInstance(); 
$autoloader->registerNamespace('Ca_'); 

Zend_Controller_Action_HelperBroker::addPrefix('Ca_Controller_Action_Helper'); 

$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
     'namespace' => "Social", 
     'basePath' => APPLICATION_PATH . "/../library", 
)); 
$resourceLoader->addResourceType('facebook', 'Facebook/', 'Facebook'); 

這是我的設置()方法在我的測試類(這是延長Zend_Test_PHPUnit_DatabaseTestCase):

public function setUp() 
{ 
    $this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); 
    $this->entityUser = new Ca_Model_Entity_User_Registered(); 
    $a = $this->getAdapter(); 
    $a->setFetchMode(Zend_Db::FETCH_OBJ); 
$a->query("SET FOREIGN_KEY_CHECKS=0;");  
parent::setUp();   
} 

現在,運行單元測試時,我得到以下錯誤的代碼這一行:

$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); 
$options = $bootstrap->getOptions(); 

Fatal error: Call to a member function getOptions() on a non-object

有誰知道是什麼原因造成的IS起訴和我如何解決它?

謝謝。

+0

的可能的複製 - http://stackoverflow.com/questions/5677462/zend-test-on-action-helper-accessing-bootstrap-getoptions-error – Rikesh 2012-07-13 11:14:02

+0

這是固定在1.10。我正在使用1.11 – Rijndael 2012-07-13 14:32:41

回答

0

我固定它。結束在bootstrap中加載應用程序配置並將其存儲在Zend_Registry中。這種方式更容易。

$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); 
Zend_Registry::set('config', $config); 
0

它看起來像你的代碼將單個參數視爲一個對象。

從文檔在:http://framework.zend.com/manual/en/zend.controller.front.html

getParam($name) allows you to retrieve a single parameter 
at a time, using $name as the identifier. 
+0

這不能解釋爲什麼它通過網絡服務器,但不在uTesting – Rijndael 2012-07-13 14:35:11

+0

這不是你問。 – Raz 2012-07-13 14:46:12