jinhin xu
jinhin xu

Reputation: 1

No output and not worked When I run [Artisan::call(...)] or [shell_exec(...)] in phpunit test, but when not in phpunit, it is ok

/**
 * @test
 */
public function xxx()
{
   $exitCode = Artisan::call('queue:work');
   //shell_exec('php artisan queue:work');
}

Run Artisan::call(...) or shell_exec(...) in PHPUnit test, it is not working.

Upvotes: 0

Views: 153

Answers (1)

pr1nc3
pr1nc3

Reputation: 8338

For your unit tests you don't use your normal laravel queue like you do in the rest of your project.

Start your queue using Queue::fake(); and then apply your test logic.

Your tests will push events in this queue and the mock workers will pick up.

Read more about mocking methods here.

Upvotes: 1

Related Questions