【发布时间】:2022-01-04 13:58:17
【问题描述】:
我正在编写需要与队列交互的测试,用例如下图;
public function testTryLogJobIsAsync()
{
// dispatch a job here
Artisan::call("queue:work");
// assert if job performed required task e.g check if a file is written to
}
作业已处理,但问题是 Artisan::call("queue:work"); 阻止了其余的执行。
有没有办法在后台运行它或运行几秒钟然后停止它以便也可以执行以下语句?
【问题讨论】:
-
这与your previous post 有关,我的 cmets 将在那里解决您的问题,因此也在这里解决。无论哪种方式,当你测试时,你做的是
$this->artisan()而不是Artisan::call。看看documentation 的解释。 -
@matiaslauriti 是的,我能够在上一篇文章中解决这个问题。对于这个问题,我选择了超时选项,我已经分享了我的解决方案。
标签: php laravel phpunit laravel-artisan