CakePHP在单元测试期间记录到活数据库 [英] CakePHP Logging to Live DB During Unit Testing
问题描述
我在Cake 2.1中使用DB记录,效果非常好。
I'm using DB logging in Cake 2.1, which works great.
我遇到的问题是当运行Unit Tests时,所有日志仍然被发送
The problem I'm having is when running Unit Tests, all logs are still getting sent to the live db rather than the test database.
所有其他数据库交互都要进行测试,除了日志记录。
All other db interactions go to test, except logging.
这是我的数据库记录器(/Lib/Log/Engine/DatabaseLogger.php)
Here's my Database logger (/Lib/Log/Engine/DatabaseLogger.php)
App::uses('CakeLogInterface', 'Log');
class DatabaseLogger implements CakeLogInterface
{
public function __construct($options = array() )
{
App::import('Model', 'Log');
$this->Log = new Log;
}
public function write($type, $message)
{
$this->Log->create();
$log['type'] = ucfirst($type);
$log['date'] = date('Y-m-d H:i:s');
$log['message'] = $message;
return $this->Log->save($log);
}
}
我确定我缺少一些基本设置
I'm sure I'm missing some basic setting here but I can't figure this out for the life of me.
推荐答案
很好,在我的情况下,问题是由于的构造函数的初始化不良。
您可以在这里检查更新解决方案:
如何选择测试DB cakePHP测试
Well, in my case the problem was caused because of a bad initialization of a constructor. You can check the update solution here: How to choose the test DB cakePHP testing
这篇关于CakePHP在单元测试期间记录到活数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!