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.6] Fix multiple notification recipients #24957

Merged
merged 3 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/Channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected function getRecipients($notifiable, $notification, $message)

return collect($recipients)->mapWithKeys(function ($recipient, $email) {
return is_numeric($email)
? [(is_string($recipient) ? $recipient : $recipient->email)]
? [$email => (is_string($recipient) ? $recipient : $recipient->email)]
: [$email => $recipient];
})->all();
}
Expand Down
43 changes: 42 additions & 1 deletion tests/Integration/Notifications/SendingMailNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function test_mail_is_sent_to_named_address()

$user->notify($notification);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nitpicking but this 4 spaces should not be here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure 👍

public function test_mail_is_sent_with_subject()
{
$notification = new TestMailNotificationWithSubject;
Expand Down Expand Up @@ -174,6 +174,36 @@ public function test_mail_is_sent_with_subject()
$user->notify($notification);
}

public function test_mail_is_sent_to_multiple_adresses()
{
$notification = new TestMailNotificationWithSubject;

$user = NotifiableUserWithMultipleAddreses::forceCreate([
'email' => 'taylor@laravel.com',
]);

$this->markdown->shouldReceive('render')->once()->andReturn('htmlContent');
$this->markdown->shouldReceive('renderText')->once()->andReturn('textContent');

$this->mailer->shouldReceive('send')->once()->with(
['html' => 'htmlContent', 'text' => 'textContent'],
$notification->toMail($user)->toArray(),
Mockery::on(function ($closure) {
$message = Mockery::mock(\Illuminate\Mail\Message::class);

$message->shouldReceive('to')->once()->with(['foo_taylor@laravel.com', 'bar_taylor@laravel.com']);

$message->shouldReceive('subject')->once()->with('mail custom subject');

$closure($message);

return true;
})
);

$user->notify($notification);
}

public function test_mail_is_sent_using_mailable()
{
$notification = new TestMailNotificationWithMailable;
Expand Down Expand Up @@ -205,6 +235,17 @@ public function routeNotificationForMail($notification)
}
}

class NotifiableUserWithMultipleAddreses extends NotifiableUser
{
public function routeNotificationForMail($notification)
{
return [
'foo_'.$this->email,
'bar_'.$this->email,
];
}
}

class TestMailNotification extends Notification
{
public function via($notifiable)
Expand Down