php - 模拟 Laravel 配置缓存
问题描述
我正在编写一个新的工匠命令,如果配置被缓存(通过),我不想运行该命令config:cache
:
class NewCommand extends Command
{
public function handle()
{
if (app()->configurationIsCached())
{
$this->error('Configuration is cached. Unable to run command');
return 1;
}
}
}
我正在尝试编写一个单元测试来涵盖这一点,但是失败了:
public function test_command_not_run_if_config_cached()
{
App::shouldReceive('configurationIsCached')
->once()
->andReturn(true);
$this->artisan('new:command')
->expectsOutput('Configuration is cached. Unable to run command');
->assertExitCode(1);
}
结果:Method configurationIsCached() from Mockery_0_Illuminate_Foundation_Application should be called exactly 1 times but called 0 times
是否有另一种方法可以模拟配置缓存在单元测试中?
解决方案
事实证明,这configurationIsCached()
在立面上是可用的App
。这目前没有记录,但将命令中的句柄函数更新为
public function handle()
{
if (App::configurationIsCached())
{
$this->error('Configuration is cached. Unable to run command');
return 1;
}
}
允许测试通过。感谢@Namosheck 指出这一点
推荐阅读
- r - 对彼此相距一定阈值距离内的多边形进行分组
- cassandra - cassandra - udt 列,数据插入问题
- javascript - 重新填充以选择选项
- html - 当我用 javascript 填充表格时,HTML 表格位置正在恶化
- react-native - 我们可以将 react-native-cli 项目(非 expo)发布到 expo.io
- webpack - 有没有办法使用 useBuiltIns 对 poyfill 进行代码拆分:用法?
- azure - MS Logic Apps:将文件添加到 SharePoint 触发器不一致
- typescript - 如何调用一个组件中的方法,它会调用另一个组件中的另一个方法?
- google-sheets - Google表格中线性回归的多个独立变量
- php - PHP Form-是否可以在同一个表名中插入多个输入字段