【发布时间】:2013-10-29 21:07:09
【问题描述】:
在我的应用程序中,我遇到了这个奇怪的错误仅在测试时,我还没有测试我的 Repo 文件夹中的任何类,但是有这个:
Call to undefined method Application_Model_Cache::getInstance() in C:\wamp\www\truCrowd_dev\application\models\Repo\User.php on line 12
我的用户回购是:
class Application_Model_Repo_User
{
private $_database;
private $_cache ;
public function __construct()
{
$this->_database = Application_Model_Database::getInstance();
$this->_cache = Application_Model_Cache::getInstance();
$this->_longCache = Application_Model_Cache::getInstance(604800);
}
我的缓存类是:
class Application_Model_Cache
{
public static function getInstance($_expiration = 7200)
{
$frontend= array(
'lifetime' => $_expiration,
'automatic_serialization' => true
);
$backend= array(
'cache_dir' => './cache/',
);
$cache = Zend_Cache::factory('Output',
'File',
$frontend,
$backend
);
return $cache;
}
}
我的测试引导是:
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production');
// 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';
Zend_Loader_Autoloader::getInstance();
我试图通过实例化它来更改 Cache 类,但我得到了相同的结果...... 我的 Database 类具有确切的结构,但我过去没有得到这个,现在我在开发中取得进展,我想进行测试并出现错误
【问题讨论】:
-
您是否在任何测试中模拟 Application_Model_Cache 类?根据您执行此操作的方式,也许模拟被用作唯一实例,因此该方法不存在。另外,您是否尝试过隔离导致错误发生的测试?
-
如果我正在测试 Cache 类?你能解释一下吗? Zend_Cache 似乎(至少在我看来)没有单例实现,所以可以创建多个实例......
-
通过在我的配置中禁用缓存来破解它,但仍然......:|
-
好的,请注意:千万不要在凌晨 3 点编程,否则请确保在编写测试脚本时在类名中附加“Test”,因为它会被覆盖...
标签: php zend-framework phpunit