1 回答

TA貢獻1851條經驗 獲得超3個贊
你錯誤地稱之為shouldHaveReceived嘲弄。
使用這種方法:
$mockedNewsLetterService->shouldHaveReceived(`method`)->with($model);
此外,為了測試我使用的作業調度bindMethod,app因此測試應該是:
public function testMethod()
{
$this->app->instance(MyModel::class,\Mockery::mock(MyModel::class,function($mock){
$mock->shouldReceive('save')->andReturn(true);
}));
$model=factory(MyModel::class)->create([
'shouldCallService'=>true,
]);
$mockedNewsLetterService=Mockery::spy(MyService::class);
$this->app->bindMethod(NewsLetterSubscribeUserJob::class.'@handle', function ($job, $app) use ($mockedNewsLetterService){
return $job->handle($mockedNewsLetterService);
});
MyJob::dispatchNow($model);
$mockedNewsLetterService->shouldHaveReceived('method')->with($model);
}
如您所見,我使用該應用程序來處理作業調度。另外,為了避免在測試期間使用第 3 方服務,我也使用dispatchNow了這樣的服務,以便我的工作不被排隊。
- 1 回答
- 0 關注
- 126 瀏覽
添加回答
舉報