I have a bunch of event listeners that listen to Laravel's queue events in order to track and update the status of a job. I am listening for the JobQueued, JobProcessing, JobProcessed, JobFailed, JobTimedOut events. An example of one of these listeners is the listener that listens to the JobProcessing event:
public function handle(JobProcessing $event): void
{
$jobUuid = $event->job->uuid();
if ($this->updater->trackableJobModelExists($jobUuid)) {
$trackableJobModel = $this->updater->retrieveTrackableJobModel($jobUuid);
$this->updater->setProcessingStatus($trackableJobModel);
}
}
I can test whether my listener listens to this event by doing this:
public function test_listens_to_laravel_job_processing_event(): void
{
Event::fake();
Event::assertListening(
JobProcessing::class,
SetTrackableJobProcessingStatus::class
);
}
I would like to test whether the event listener works and updates the record in the database. I tried:
public function test_updates_status_to_processing(): void
{
$eventListener = new SetTrackableJobProcessingStatus(new TrackableJobUpdater());
$eventListener->handle(new JobProcessing('default', new TrackedJob()));
// ... assertions
}
But I get the error/warning:
Expected parameter of type '\Illuminate\Contracts\Queue\Job', '\App\Tests\Jobs\TrackedJob' provided
What would be the proper way to test something like this?