简体   繁体   English

单元测试Zendframework:无法将元数据保存到metadataCache

[英]Unit Test Zendframework: Failed saving metadata to metadataCache

I am trying to setup a controller unit test but I get the following error: 我正在尝试设置控制器单元测试,但出现以下错误:

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()
...

In my bootstrap I have APC cache: 在我的引导程序中,我具有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;
}

I am running the test below: 我正在运行以下测试:

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

Why I am getting this error? 为什么我收到此错误? seems php cli can't use caching but the application runs normally on browser 似乎php cli无法使用缓存,但是应用程序可以在浏览器上正常运行

APC is disabled for PHP CLI by default, adding the following config line in php.ini solves the issue. 默认情况下,PHP CLI禁用APC,在php.ini中添加以下配置行即可解决此问题。

apc.enable_cli=1

This configuration can only be set in php.ini or httpd.conf. 只能在php.ini或httpd.conf中设置此配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM