When using "On-Demand Notifications" a AnonymousNotifiable is created and passed to the Notification system.
When in test using Notification Fakes or the notificationsFor method expects $notifiable to be a Notifiable class but it will be a string.
ErrorException: get_class() expects parameter 1 to be object, string given
vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/NotificationFake.php
Use Notification::route('mail', '[email protected]')->notify(new InvoicePaid($invoice)); to send a notification
write a test that triggers that function
use the Notification Fake, Notification::fake();
the above error is produced
* Looks like there was a similar issue in the past that may have crept back in #20936 *
Ignore this. Looks like there is an example of it working in PR to fix older issue:
https://github.com/laravel/framework/pull/21379/commits/5ee629cb2bf993a2102c35404803c74ddbfeddae
$emailSentTo = '[email protected]';
Notification::assertSentTo(
new AnonymousNotifiable(),
WhateverNotificationYourTesting::class,
function ($notification, $channels, $notifiable) use ($emailSentTo) {
return $notifiable->routes['mail'] === $emailSentTo;
}
);
Most helpful comment
Ignore this. Looks like there is an example of it working in PR to fix older issue:
https://github.com/laravel/framework/pull/21379/commits/5ee629cb2bf993a2102c35404803c74ddbfeddae