【发布时间】:2020-09-18 21:17:01
【问题描述】:
我在 laravel 项目中实现了缓存标签,我的控制器中有这样的东西:
if (Cache::tags(['api'])->has('someKey')) {
return new JsonResponse(Cache::tags(['api'])->get('someKey'));
}
我想编写一个 phpunit 测试来测试这段代码:我模拟了 laravel 文档中的缓存,但我没有找到任何关于如何在模拟缓存上使用 tags 的信息
我试过了:
Cache::tags(['api'])->shouldReceive('has')->with('someKey')->andReturn(true)->once();
或
Cache::shouldReceive('has')->tags(['api'])->with('someKey')->andReturn(true)->once();
但这些都不起作用,我得到了Call to undefined method Illuminate\Cache\ArrayStore::shouldReceive() 或
call_user_func_array() expects parameter 1 to be a valid callback, class 'Mockery\Expectation' does not have a method 'tags'
有人知道吗?非常感谢:)
【问题讨论】:
标签: laravel caching mocking phpunit