0

I am trying to test that some data gets populated on a page that is done by a job. In my testing environment, the queue isn't running.

Is there any way to manually run the jobs from a function in a controller? I have retrieved all Jobs from my database by doing the following:

$allJobs = Jobs::all();

foreach ($allJobs as $job) {
     // $job->handle(); ????
}

What I would like is to iterate over each job and process them myself. My test suite can wait for these jobs to be processed. I can't seem to find any documentation about this. Thanks!

party-ring
  • 1,761
  • 1
  • 16
  • 38

1 Answers1

0

If the goal is to be able to write tests for your jobs, it is fairly simple:

public function testJobsEvents()
{
       $job = new \App\Jobs\YourJob;
       $job->handle();

       // Assert the side effect of your job...
}
Alex Harris
  • 6,172
  • 2
  • 32
  • 57