boxxroom's avatar

No notifiable given. (PHPUnit / artisan test)

I seem to be experiencing (what I feel) is weird behaviour with a given test.

The weird behaviour being when tested in isolation I get green. When testing the entire suit and/or test folder it lives in it fails.

No notifiable given.

The Test:


/** @test */
    public function it_can_send_a_notification_when_a_user_has_completed_enrolment()
    {
        $this->withoutExceptionHandling();

        $this->seed([StatusSeeder::class, AccountTypeSeeder::class]);

        $registeredUser = User::factory()->hasProfile()->hasAccount([
            'account_type_id' => AccountType::learner(),
            'status_id' => Status::awaitingApproval(),
        ])->create(['email' => '[email protected]']);

        $assessors = User::factory()->hasProfile()->hasAccount([
            'account_type_id' => AccountType::assessor(),
            'status_id' => Status::approved()
        ])->create(['email' => '[email protected]']);

        $assessors->account->assign($registeredUser);

        $this->assertDatabaseHas('account_members', [
            'account_id' => $assessors->account->id,
            'user_id' => $registeredUser->id
        ]);

        Notification::fake();

        $listener = new SendEmailEnrolmentCompleteNotification();
        $listener->handle(new EnrolmentStatus($registeredUser, $registeredUser->account->status));

        Notification::assertSentTo($registeredUser->account->reviewers, EnrolmentCompleteNotification::class, function ($event) use ($assessors) {
            return $event->user->account->reviewers->contains($assessors);
        });
    }

Attached results of test when ran in isolation and suit.

test-in-isolation Test-suit-grouped-folder-PHPUnit Test-suit-grouped-folder-artisan

0 likes
0 replies

Please or to participate in this conversation.