2012-08-01 47 views
1

我想設置一個控制器單元測試,但我得到以下錯誤:單元測試Zendframework:未能保存元數據metadataCache

InscricaoControllerTest::testInscricaoPage() 
Zend_Controller_Exception: Failed saving metadata to metadataCache#0 [internal function]: PHPUnit_Util_ErrorHandler::handleError(1024, 'Failed saving m...', 'C:\xampp\ZendFr...', 838, Array) 
#1 C:\xampp\ZendFramework-1.11.12\library\Zend\Db\Table\Abstract.php(838): trigger_error('Failed saving m...', 1024) 
#2 C:\xampp\ZendFramework-1.11.12\library\Zend\Db\Table\Abstract.php(874): Zend_Db_Table_Abstract->_setupMetadata() 
#3 C:\xampp\ZendFramework-1.11.12\library\Zend\Db\Table\Abstract.php(982): Zend_Db_Table_Abstract->_setupPrimaryKey() 
#4 C:\xampp\ZendFramework-1.11.12\library\Zend\Db\Table\Select.php(100): Zend_Db_Table_Abstract->info() 
#5 C:\xampp\ZendFramework-1.11.12\library\Zend\Db\Table\Select.php(78): Zend_Db_Table_Select->setTable(Object(Application_Model_DbTable_TipoUsuario)) 
#6 C:\xampp\ZendFramework-1.11.12\library\Zend\Db\Table\Abstract.php(1018): Zend_Db_Table_Select->__construct(Object(Application_Model_DbTable_TipoUsuario)) 
#7 C:\htdocs\sgsa\application\models\DbTable\TipoUsuario.php(19): Zend_Db_Table_Abstract->select() 
#8 C:\htdocs\sgsa\library\Sistema\Controller\Plugin\Acl.php(10): Application_Model_DbTable_TipoUsuario->getTipoUsuario() 
#9 C:\xampp\ZendFramework-1.11.12\library\Zend\Controller\Plugin\Broker.php(309): Sistema_Controller_Plugin_Acl->preDispatch(Object(Zend_Controller_Request_HttpTestCase)) 
#10 C:\xampp\ZendFramework-1.11.12\library\Zend\Controller\Front.php(941): Zend_Controller_Plugin_Broker->preDispatch(Object(Zend_Controller_Request_HttpTestCase)) 
#11 C:\xampp\ZendFramework-1.11.12\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() 
#12 C:\xampp\ZendFramework-1.11.12\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 
#13 C:\xampp\ZendFramework-1.11.12\library\Zend\Test\PHPUnit\ControllerTestCase.php(206): Zend_Application->run() 
#14 C:\htdocs\sgsa\tests\application\controllers\InscricaoControllerTest.php(11): Zend_Test_PHPUnit_ControllerTestCase->dispatch('/inscricao') 
#15 [internal function]: InscricaoControllerTest->testInscricaoPage() 
... 

在我引導我有APC緩存:

protected function _initCache() { 
    $frontendOptions = array(
     'lifetime' => 7200, // cache lifetime of 2 hours 
     'automatic_serialization' => true 
    ); 
    $backendOptions = array(
      //'cache_dir' => APPLICATION_PATH. '/../data/cache/' // Directory where to put the cache files 
    ); 
    // getting a Zend_Cache_Core object 
    $cache = Zend_Cache::factory('Core', 'Apc', $frontendOptions, $backendOptions); 
    Zend_Db_Table::setDefaultMetadataCache($cache); 
    Zend_Locale::setCache($cache); 
    Zend_Date::setOptions(array('cache' => $cache)); 
    return $cache; 
} 

我運行下面的測試:

public function testInscricaoPage() { 
    $this->dispatch('/inscricao'); 
    $this->assertResponseCode(200); 
    $this->assertQueryContentContains('h1', 'Inscrição'); 
} 

爲什麼我得到這個錯誤?似乎php cli不能使用緩存,但應用程序在瀏覽器上正常運行

回答

1

默認情況下,PHP CLI禁用APC,在php.ini中添加以下配置行可解決此問題。

apc.enable_cli=1 

此配置只能在php.ini或httpd.conf中設置。

+1

對'/ tmp/zend_cache *'也可能是不正確的權限(至少它是給我的)。 https://twitter.com/meonkeys/status/453630634280230912 – 2014-04-08 21:07:42