相关疑难解决方法(0)

stringContains 在 Laravel Log 外观中匹配的参数 shouldReceive

我在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'))

phpunit mocking laravel mockery laravel-5

2
推荐指数
1
解决办法
2336
查看次数

标签 统计

laravel ×1

laravel-5 ×1

mockery ×1

mocking ×1

phpunit ×1