Laravel - Mocking - On Demand Notifications
If the code you are testing sends on-demand notifications, you will need to assert that the notification was sent to an Illuminate\Notifications\AnonymousNotifiable
instance:
use Illuminate\Notifications\AnonymousNotifiable;
Notification::assertSentTo(
new AnonymousNotifiable, OrderShipped::class
);
By passing a closure as the third argument to the notification assertion methods, you may determine if an on-demand notification was sent to the correct "route" address:
Notification::assertSentTo(
new AnonymousNotifiable,
OrderShipped::class,
function ($notification, $channels, $notifiable) use ($user) {
return $notifiable->routes['mail'] === $user->email;
}
);