如何测试laravel连续工作?

时间:2018-03-09 14:44:43

标签: laravel testing queue jobs

我正在使用 Laravel 5.6 ,并应为某些功能创建功能测试。在某些条件下,如果第一个作业从第一个执行,我如何测试2个作业的调度。

它看起来像这样:

class FirstJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;


    public function handle()
    {
        dispatch(new SecondJob());
    }
}

顺序断言无法看到第二个作业。

Queue::assertPushed(FirstJob::class); //断言

Queue::assertPushed(SecondJob::class); //未断言

1 个答案:

答案 0 :(得分:2)

只需发送firstJob,然后调用handle()方法

即可

示例:

    $new_job = new FirstJob();
    $new_job->dispatch();

    Queue::assertPushed(FirstJob::class,
       // check some job property against the expected
    });

    $new_job->handle();

    Queue::assertPushed(SecondJob::class,
       // check some job property against the expected
    });