diff --git a/src/Notifications/DoctrineChannel.php b/src/Notifications/DoctrineChannel.php index f808d358..ba78c5a9 100644 --- a/src/Notifications/DoctrineChannel.php +++ b/src/Notifications/DoctrineChannel.php @@ -6,6 +6,7 @@ use Doctrine\Persistence\ManagerRegistry; use Illuminate\Notifications\Notification as LaravelNotification; +use InvalidArgumentException; use LaravelDoctrine\ORM\Exceptions\NoEntityManagerFound; use RuntimeException; @@ -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); } diff --git a/tests/Feature/Notifications/DoctrineChannelTest.php b/tests/Feature/Notifications/DoctrineChannelTest.php index 441c4452..e74890c0 100644 --- a/tests/Feature/Notifications/DoctrineChannelTest.php +++ b/tests/Feature/Notifications/DoctrineChannelTest.php @@ -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; @@ -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()); }