Skip to content
loading...

re: How I can test that one Laravel job dispatches an another one on testing? VIEW POST

FULL DISCUSSION
 

Posted this answer on StackOverflow, too, but here it is for discussion. 😄 Laravel has queue mocks/fakes that will handle that. Try this:

namespace Tests;

use Illuminate\Foundation\Testing\TestCase;
use Illuminate\Support\Facades\Queue;
use App\Jobs\MyWorker;
use App\Jobs\AnotherJob;

class TestMyWorker extends TestCase
{
  public function testDispachesAnotherJob()
  {
    Queue::fake();
    MyWorker::dispatchNow();
    Queue::assertPushed(MyWorker::class);
    Queue::assertPushed(AnotherJob::class);
  }
}
code of conduct - report abuse