我在Laravel 文档中看到可以设置这样的测试期望:
Cache::shouldReceive('get')
->once()
->with('key')
->andReturn('value');
Run Code Online (Sandbox Code Playgroud)
然后我在PHPunit 文档中看到灵活的参数匹配是可能的,如下所示:$this->stringContains('Something')。
但是当我编辑我的测试时:
Log::shouldReceive('error')
->once();
->with($this->stringContains('Contact does not exist'));
Run Code Online (Sandbox Code Playgroud)
...然后我收到以下错误:
Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_1_Illuminate_Log_Writer::error("Contact does not exist blah blah etc").
Either the method was unexpected or its arguments matched no expected argument list for this method
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现我的目标(通过灵活的参数匹配Log::shouldReceive)?
PS我也尝试过->with(\PHPUnit\Framework\Assert::stringContains('Contact does not exist'))。