From 595c107516f82e33a7726e7fefd84b4ffdc6da98 Mon Sep 17 00:00:00 2001 From: 77web Date: Mon, 10 Mar 2025 23:12:40 +0900 Subject: [PATCH] IlluminateRegistry::getManager() now throws exception when manager for the specified name does not exist in the registry. --- src/Notifications/DoctrineChannel.php | 11 ++++++++--- tests/Feature/Notifications/DoctrineChannelTest.php | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) 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()); }