Ser*_*i H 1 testing queue jobs laravel
我正在使用Laravel 5.6,应该为某些功能创建功能测试。在某些条件下,如果从第一个作业执行第二个作业,我如何测试两个作业的调度。
它看起来像这样:
class FirstJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
dispatch(new SecondJob());
}
}
Run Code Online (Sandbox Code Playgroud)
顺序断言看不到第二个作业。
Queue::assertPushed(FirstJob::class);// 断言
Queue::assertPushed(SecondJob::class);// 未断言
只需调度firstJob然后调用该handle()方法
例子:
$new_job = new FirstJob();
$new_job->dispatch();
Queue::assertPushed(FirstJob::class, function(){
// check some job property against the expected
});
$new_job->handle();
Queue::assertPushed(SecondJob::class, function(){
// check some job property against the expected
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3032 次 |
| 最近记录: |