【问题标题】:run blocking artisan call in the background during tests - Laravel在测试期间在后台运行阻止工匠调用 - Laravel
【发布时间】: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


【解决方案1】:

我选择了在测试期间启动和停止 artisan 命令的选项,在 Windows 操作系统上我通过以下方式实现了它; 变化自

Artisan::call("queue:work");

exec('"%PROGRAMFILES%\Git\bin\bash.exe" --login -i -c "timeout 5 php artisan queue:work"');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    • 2010-11-04
    • 1970-01-01
    相关资源
    最近更新 更多