【发布时间】:2018-04-05 22:06:21
【问题描述】:
我在Laravel docs 中看到可以像这样设置测试期望:
Cache::shouldReceive('get')
->once()
->with('key')
->andReturn('value');
然后我在PHPunit docs 中看到,灵活的参数匹配可以像这样:$this->stringContains('Something')。
但是当我编辑我的测试时:
Log::shouldReceive('error')
->once();
->with($this->stringContains('Contact does not exist'));
...然后我收到以下错误:
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
我怎样才能实现我的目标(在Log::shouldReceive 中使用灵活的参数匹配)?
附:我也试过->with(\PHPUnit\Framework\Assert::stringContains('Contact does not exist'))。
【问题讨论】:
标签: laravel laravel-5 mocking phpunit mockery