Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[12.x] feat: Add ability to override SendQueuedNotifications job class #55942

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

Open
wants to merge 3 commits into
base: 12.x
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion 6 src/Illuminate/Notifications/NotificationSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ protected function queueNotification($notifiables, $notification)
}

$this->bus->dispatch(
(new SendQueuedNotifications($notifiable, $notification, [$channel]))
$this->manager->getContainer()->make(SendQueuedNotifications::class, [
'notifiables' => $notifiable,
'notification' => $notification,
'channels' => [$channel],
])
->onConnection($connection)
->onQueue($queue)
->delay(is_array($delay) ? ($delay[$channel] ?? null) : $delay)
Expand Down
22 changes: 22 additions & 0 deletions 22 tests/Notifications/NotificationChannelManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\SendQueuedNotifications;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
use Mockery as m;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -159,6 +161,26 @@ public function testNotificationCanBeQueued()

$manager->send([new NotificationChannelManagerTestNotifiable], new NotificationChannelManagerTestQueuedNotification);
}

public function testSendQueuedNotificationsCanBeOverrideViaContainer()
{
$container = new Container;
$container->instance('config', ['app.name' => 'Name', 'app.logo' => 'Logo']);
$container->instance(Dispatcher::class, $events = m::mock());
$container->instance(Bus::class, $bus = m::mock());
$bus->shouldReceive('dispatch')->with(m::type(TestSendQueuedNotifications::class));
$container->bind(SendQueuedNotifications::class, TestSendQueuedNotifications::class);
Container::setInstance($container);
$manager = m::mock(ChannelManager::class.'[driver]', [$container]);
$events->shouldReceive('listen')->once();

$manager->send([new NotificationChannelManagerTestNotifiable], new NotificationChannelManagerTestQueuedNotification);
}
}

class TestSendQueuedNotifications implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
}

class NotificationChannelManagerTestNotifiable
Expand Down
5 changes: 5 additions & 0 deletions 5 tests/Notifications/NotificationSenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function testItCanSendQueuedNotificationsWithAStringVia()
{
$notifiable = m::mock(Notifiable::class);
$manager = m::mock(ChannelManager::class);
$manager->shouldReceive('getContainer')->andReturn(app());
$bus = m::mock(BusDispatcher::class);
$bus->shouldReceive('dispatch');
$events = m::mock(EventDispatcher::class);
Expand Down Expand Up @@ -55,6 +56,7 @@ public function testItCannotSendNotificationsViaDatabaseForAnonymousNotifiables(
{
$notifiable = new AnonymousNotifiable;
$manager = m::mock(ChannelManager::class);
$manager->shouldReceive('getContainer')->andReturn(app());
$bus = m::mock(BusDispatcher::class);
$bus->shouldNotReceive('dispatch');
$events = m::mock(EventDispatcher::class);
Expand All @@ -76,6 +78,7 @@ public function testItCanSendQueuedNotificationsThroughMiddleware()
});
$events = m::mock(EventDispatcher::class);
$events->shouldReceive('listen')->once();
$manager->shouldReceive('getContainer')->andReturn(app());

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

Expand All @@ -86,6 +89,7 @@ public function testItCanSendQueuedMultiChannelNotificationsThroughDifferentMidd
{
$notifiable = m::mock(Notifiable::class);
$manager = m::mock(ChannelManager::class);
$manager->shouldReceive('getContainer')->andReturn(app());
$bus = m::mock(BusDispatcher::class);
$bus->shouldReceive('dispatch')
->once()
Expand Down Expand Up @@ -114,6 +118,7 @@ public function testItCanSendQueuedWithViaConnectionsNotifications()
{
$notifiable = new AnonymousNotifiable;
$manager = m::mock(ChannelManager::class);
$manager->shouldReceive('getContainer')->andReturn(app());
$bus = m::mock(BusDispatcher::class);
$bus->shouldReceive('dispatch')
->once()
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.