Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Notification fake accepts custom channels #28969

Merged
merged 1 commit into from Jun 27, 2019

Conversation

Projects
None yet
2 participants
@dwightwatson
Copy link
Contributor

commented Jun 27, 2019

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

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@dwightwatson dwightwatson deleted the dwightwatson:notification-fake branch Jun 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.