We are sending a slack message to our team channel hence not using a notifiable instance. This is how I did it-
Notification::route('slack', env('SLACK_URL'))
->notify(new StaffNotification());
And in StaffNotification
public function toSlack() {
return (new SlackMessage)->content('New Staff Message.');
}
How should I test StaffNotification as all the assert available are accepting the first parameter as notifiable?
Laravel creates an AnonymousNotifiable behind the scene when you have not a notifiable in your model, and you can use it:
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Facades\Notification;
class NotificationsTest extends TestCase
{
public function testSend()
{
Notification::fake();
//perform your code
Notification::assertSentTo(new AnonymousNotifiable(), StaffNotification::class);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With