Forked from djaiss/laravel-test-job-dispatches-other-jobs.php
Last active
September 26, 2023 13:33
-
-
Save MizouziE/d66aeddd5abc783da142ce117a5f29ea 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 | |
{ | |
// The FirstJob() dispatched another job, called SecondJob(). | |
// We need to omit this job from the Queue facade's fake method so we can assert that | |
// the second job was pushed. | |
Queue::fake()->except([FirstJob::class]); | |
// Now we may dispatch the first job normally | |
FirstJob::dispatch(); | |
// Having been allowed to operate normally, the first job will push second job to the fake queue. | |
Queue::assertPushed(SecondJob::class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment