Skip to content

Instantly share code, notes, and snippets.

@djaiss
Created August 15, 2020 14:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save djaiss/b59b872832be5027cc9dfca6a776a469 to your computer and use it in GitHub Desktop.
Save djaiss/b59b872832be5027cc9dfca6a776a469 to your computer and use it in GitHub Desktop.
How to test that a job dispatches another job in Laravel
<?php
namespace Tests\Unit\Jobs;
use Tests\TestCase;
use Illuminate\Support\Facades\Queue;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class FirstJobTest extends TestCase
{
use DatabaseTransactions;
/** @test */
public function it_asks_every_employee_to_rate_the_given_manager(): void
{
Queue::fake();
// The FirstJob() dispatched another job, called SecondJob().
// We need to manually dispatch and handle this job so we can assert that
// the second job was pushed.
$job = new FirstJob();
$job->dispatch();
$job->handle();
Queue::assertPushed(SecondJob::class, function ($job) use ($michael) {
return $job->manager->id === $michael->id;
});
}
}
@djaiss
Copy link
Author

djaiss commented Aug 20, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment