Created
August 15, 2020 14:06
-
-
Save djaiss/b59b872832be5027cc9dfca6a776a469 to your computer and use it in GitHub Desktop.
How to test that a job dispatches another job in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment