Skip to content

Commit

Permalink
Merge pull request #27710 from driesvints/fix-notification-sender
Browse files Browse the repository at this point in the history
[5.8] Fix a bug with string via in queued notifications
  • Loading branch information
taylorotwell authored Feb 28, 2019
2 parents 66b56bd + 586345a commit ee6a5e0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/NotificationSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected function queueNotification($notifiables, $notification)
foreach ($notifiables as $notifiable) {
$notificationId = Str::uuid()->toString();

foreach ($original->via($notifiable) as $channel) {
foreach ((array) $original->via($notifiable) as $channel) {
$notification = clone $original;

$notification->id = $notificationId;
Expand Down
54 changes: 54 additions & 0 deletions tests/Notifications/NotificationSenderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Illuminate\Tests\Notifications;

use Mockery as m;
use Illuminate\Bus\Queueable;
use PHPUnit\Framework\TestCase;
use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Notifications\NotificationSender;
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;

class NotificationSenderTest extends TestCase
{
protected function tearDown(): void
{
parent::tearDown();

m::close();
}

public function test_it_can_send_queued_notifications_with_a_string_via()
{
$notifiable = m::mock(Notifiable::class);
$manager = m::mock(ChannelManager::class);
$bus = m::mock(BusDispatcher::class);
$bus->shouldReceive('dispatch');
$events = m::mock(EventDispatcher::class);

$sender = new NotificationSender($manager, $bus, $events);

$sender->send($notifiable, new DummyQueuedNotificationWithStringVia());
}
}

class DummyQueuedNotificationWithStringVia extends Notification implements ShouldQueue
{
use Queueable;

/**
* Get the notification channels.
*
* @param mixed $notifiable
* @return array|string
* @return array|string
*/
public function via($notifiable)
{
return 'mail';
}
}

0 comments on commit ee6a5e0

Please sign in to comment.