我正在为 Laravel 应用程序编写测试,特别是针对在控制台上写入大量日志消息的进程。
例如
Log::info('Process starts', [
'process_name' => 'product_import',
'data' => // a huge text containing json_encode of the given message object
]
Run Code Online (Sandbox Code Playgroud)
当我运行 phpunit 时,我在控制台上看到所有这些烦人的日志消息。有没有办法禁用或以某种方式停止这些日志消息?
我想模拟在我的测试中Config::get('specific_key')返回一个'specific_value'。所以我写了下面的代码:
Config::shouldReceive('get')
->with('specific_key')
->andReturn('specific_value');
Config::makePartial();
Run Code Online (Sandbox Code Playgroud)
这会起作用:如果我添加 dd(Config::get('specific_key'))我将收到'specific_value'.
但是,如果我这样做 dd(Config::get('another_key')),我不会收到任何值(我猜是因为模拟不希望将此键作为参数)。
所以我的问题是:有没有办法模拟 Config 的 get() 方法只为特定键返回特定值(并从配置文件中返回任何其他键的正常值)?