【问题标题】:How does one turn off logging during unit testing in CakePHP 2.x?在 CakePHP 2.x 的单元测试期间如何关闭日志记录?
【发布时间】:2013-02-23 23:31:36
【问题描述】:

例如,如果您正在对模型进行单元测试,并且在该模型中使用 CakePHP 的 CakeLog 便捷方法(可能测试预期的异常等):

CakeLog::warning('This is a warning');

Cake 不仅会在您的测试期间在命令行中输出此内容,还会将错误添加到 logs/error.log。

我需要完成以下两件事之一:

  1. 在单元测试期间关闭日志记录
  2. 模拟 CakeLog 类或存根 Model->log()(继承自 Object->log)

精明的 CakePHP 开发人员如何完成这两件事之一?

相关:Using DB logging and doing said logging to your test database where such a thing wouldn't bother you...

【问题讨论】:

    标签: cakephp cakephp-2.3


    【解决方案1】:

    在测试的顶部,将CakeLog::drop(logger_name); 放入disable logging on the logger_name

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      • 2011-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多