create([ 'contact_email' => 'admin@example.com', ]); $job = new SendTenantCreditsLowNotification($tenant->id, balance: 5, threshold: 10); $job->handle(); Notification::assertSentOnDemand(TenantCreditsLowNotification::class, function ($notification, $channels, $notifiable) { return in_array('mail', $channels, true) && ($notifiable->routes['mail'] ?? null) === 'admin@example.com'; }); $tenant->refresh(); $this->assertCount(1, $tenant->notificationLogs); $log = $tenant->notificationLogs()->first(); $this->assertSame('credits_low', $log->type); $this->assertSame('sent', $log->status); $this->assertSame('admin@example.com', $log->recipient); $this->assertNotNull($log->sent_at); } }