Skip to content

Commit b7b55d0

Browse files
axlontaylorotwell
andauthored
[7.x] Fix SendQueuedNotifications notifiables property type (#31675)
* The notifiables property is now always a collection, as it's documentation suggests * Update SendQueuedNotifications.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent f8598a7 commit b7b55d0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Illuminate/Notifications/SendQueuedNotifications.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Contracts\Queue\ShouldQueue;
77
use Illuminate\Queue\InteractsWithQueue;
88
use Illuminate\Queue\SerializesModels;
9+
use Illuminate\Support\Collection;
910

1011
class SendQueuedNotifications implements ShouldQueue
1112
{
@@ -57,8 +58,8 @@ class SendQueuedNotifications implements ShouldQueue
5758
public function __construct($notifiables, $notification, array $channels = null)
5859
{
5960
$this->channels = $channels;
60-
$this->notifiables = $notifiables;
6161
$this->notification = $notification;
62+
$this->notifiables = Collection::wrap($notifiables);
6263
$this->tries = property_exists($notification, 'tries') ? $notification->tries : null;
6364
$this->timeout = property_exists($notification, 'timeout') ? $notification->timeout : null;
6465
}

tests/Notifications/NotificationSendQueuedNotificationTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Notifications\ChannelManager;
66
use Illuminate\Notifications\SendQueuedNotifications;
7+
use Illuminate\Support\Collection;
78
use Mockery as m;
89
use PHPUnit\Framework\TestCase;
910

@@ -18,7 +19,11 @@ public function testNotificationsCanBeSent()
1819
{
1920
$job = new SendQueuedNotifications('notifiables', 'notification');
2021
$manager = m::mock(ChannelManager::class);
21-
$manager->shouldReceive('sendNow')->once()->with('notifiables', 'notification', null);
22+
$manager->shouldReceive('sendNow')->once()->withArgs(function ($notifiables, $notification, $channels) {
23+
return $notifiables instanceof Collection && $notifiables->toArray() === ['notifiables']
24+
&& $notification === 'notification'
25+
&& $channels === null;
26+
});
2227
$job->handle($manager);
2328
}
2429
}

0 commit comments

Comments
 (0)