Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

James_Moore's avatar

Testing command that sends two different notifications to two different users

Currently the following test fails, removed a lot of code so its less to read just trying to get the point across.

The expected [App\Notifications\AnotherReActivationNotification] notification was not sent.
   ├ Failed asserting that false is true.

But another test that tests the first notification is sent passes.

    /** @test */
    public function this_is_my_test() {
        Notification::fake();

        $suspendedParticipant = // a user model

        $manager = // users manager

        Artisan::call('the command');

        Notification::assertSentTo($manager, AnotherReActivationNotification::class);
    }

some code from command

        $participants->each(function ($participant) {
            $participant->notify(new ReActivationNotification());

	    $participant->manager->notify(new AnotherReActivationNotification())
        });
0 likes
2 replies
drewdan's avatar
drewdan
Best Answer
Level 15

Just a stab in the dark here. Do you need to pass the environment to the artisan call? I guess you've got a test env, so would it need to be Artisan::call('the command --env=testing')

1 like

Please or to participate in this conversation.