Skip to content

[5.8] Notification fake accepts custom channels#28969

Merged
taylorotwell merged 1 commit into
laravel:5.8from
dwightwatson:notification-fake
Jun 27, 2019
Merged

[5.8] Notification fake accepts custom channels#28969
taylorotwell merged 1 commit into
laravel:5.8from
dwightwatson:notification-fake

Conversation

@dwightwatson
Copy link
Copy Markdown
Contributor

When dispatching notifications now you have the option to pass in the channels you want to deliver that notification - overriding the channels returned from the notification's via method.

Unfortunately the NotificationFake doesn't support this use case - and it records the notifications having been sent over their default channels instead. This means that you cannot test that the notification was sent over the given channel instead.

This change is simply reflecting the implementation in NotificationSender into the fake.

Notification::fake();

$user->notify(new MessageReceived($message), [NexmoVoiceChannel::class]);

Notification::assertSentTo($user, MessageReceived::class, function ($notification, $channels) {
    return $channels[0] === NexmoVoiceChannel::class;
]);

For some additional context, my use-case is that the notification is usually delivered by email/text however a user might want to receive it via a phone call instead. An alternative approach might be to pass that in through the notification's constructor instead but that felt a little odd.

@dwightwatson dwightwatson changed the title Notification fake accepts custom channels [5.8] Notification fake accepts custom channels Jun 27, 2019
@taylorotwell taylorotwell merged commit 896906b into laravel:5.8 Jun 27, 2019
@dwightwatson dwightwatson deleted the notification-fake branch June 28, 2019 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants