How to test a Queued Closure Hi,
I'm learning to work using TDD and Laravel. Everything is going great so far, but now I have a doubt about how to test a Queued Closure is dispatched.
Any clues?
Laravel has a lot of helpers for testing your jobs. For example
// ActionJobTest.php
Bus::fake();
// Perform your action
Bus::assertDispatched(ActionJob::class, function ($job) {
return $job->data['action'] === 'deleteAllFiles';
});
However, this doesn't support closure based jobs.
My recommendation would be creating a job class, which makes this more testable as well ;)
Does it make sense if I'm only delaying a single model method?
I would always create a class for a job. This will give you a clear view of all the jobs you have as well in your app/Jobs directory. You can't reuse it as a callback as well.
Please sign in or create an account to participate in this conversation.