DEV Community

Discussion on: How I can test that one Laravel job dispatches an another one on testing?

Collapse
 
martyhimmel profile image
Martin Himmel

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);
  }
}