Unit Test Zendframework: Failed saving metadata to metadataCache

3.4k views Asked by At

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:

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

1

There are 1 answers

1
dextervip On BEST ANSWER

APC is disabled for PHP CLI by default, adding the following config line in php.ini solves the issue.

apc.enable_cli=1

This configuration can only be set in php.ini or httpd.conf.