Skip to content
Merged
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
11 changes: 8 additions & 3 deletions src/Notifications/DoctrineChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Persistence\ManagerRegistry;
use Illuminate\Notifications\Notification as LaravelNotification;
use InvalidArgumentException;
use LaravelDoctrine\ORM\Exceptions\NoEntityManagerFound;
use RuntimeException;

Expand All @@ -25,9 +26,13 @@ public function send(mixed $notifiable, LaravelNotification $notification): void
$entity = $this->getEntity($notifiable, $notification);

if (method_exists($notifiable, 'routeNotificationForDoctrine')) {
$em = $this->registry->getManager(
$notifiable->routeNotificationFor('doctrine', $notification),
);
try {
$em = $this->registry->getManager(
$notifiable->routeNotificationFor('doctrine', $notification),
);
} catch (InvalidArgumentException) {
$em = null;
}
} else {
$em = $this->registry->getManagerForClass($entity::class);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Notifications/DoctrineChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use InvalidArgumentException;
use LaravelDoctrine\ORM\Exceptions\NoEntityManagerFound;
use LaravelDoctrine\ORM\Notifications\DoctrineChannel;
use LaravelDoctrineTest\ORM\Assets\Notifications\CustomNotifiableStub;
Expand Down Expand Up @@ -90,7 +91,7 @@ public function testItShouldThrowExceptionWhenItDoesNotFindAnEm(): void

$this->registry->shouldReceive('getManager')
->with('custom')
->andReturnNull();
->andThrow(InvalidArgumentException::class);

$this->channel->send(new CustomNotifiableStub(), new NotificationStub());
}
Expand Down
Loading