单元测试Zendframework:将元数据保存到metadataCache失败

时间:2012-08-01 03:01:59

标签: zend-framework zend-cache zend-test

我正在尝试设置控制器单元测试但是我收到以下错误:

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

在我的bootstrap中我有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 个答案:

答案 0 :(得分:1)

默认情况下,对于PHP CLI禁用APC,在php.ini中添加以下配置行解决了这个问题。

apc.enable_cli=1

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