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.3] Added support for notifications MailChannel using messages that implements Mailable contract #15318

Merged
merged 5 commits into from
Sep 7, 2016
Merged
Changes from 1 commit
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
34 changes: 34 additions & 0 deletions tests/Notifications/NotificationMailChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ public function testMessageWithToAddress()

$channel->send($notifiable, $notification);
}

public function testMessageWithMailableContract()
{
$notification = new NotificationMailChannelTestNotificationWithMailableContract;
$notifiable = new NotificationMailChannelTestNotifiable;

$channel = new Illuminate\Notifications\Channels\MailChannel(
$mailer = Mockery::mock(Illuminate\Contracts\Mail\Mailer::class)
);

$mailer->shouldReceive('send')->once();
Copy link
Member

Choose a reason for hiding this comment

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

Mailer would receive send anyway, I think you need to test that the Mailable object would receive send in this case.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, didn't notice the test below.


$channel->send($notifiable, $notification);
}
}

class NotificationMailChannelTestNotifiable
Expand Down Expand Up @@ -272,3 +286,23 @@ public function toMail($notifiable)
->to('jeffrey@laracasts.com');
}
}

class NotificationMailChannelTestNotificationWithMailableContract extends Notification
{
public function toMail($notifiable)
{
$mock = Mockery::mock(Illuminate\Contracts\Mail\Mailable::class);

$mock->shouldReceive('send')->once()->with(Mockery::on(function($mailer) {
if (! ($mailer instanceof \Illuminate\Contracts\Mail\Mailer)) {
Copy link
Member

Choose a reason for hiding this comment

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

No leading slash please. Also, no extra brackets are needed.

return false;
}

$mailer->send('notifications::email-plain');

return true;
}));

return $mock;
}
}