diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineCloseConnectionMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineCloseConnectionMiddleware.php index 6520ac0a35..0996859221 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineCloseConnectionMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineCloseConnectionMiddleware.php @@ -12,8 +12,8 @@ namespace Symfony\Bridge\Doctrine\Messenger; use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Messenger\Envelope; +use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; use Symfony\Component\Messenger\Middleware\StackInterface; @@ -40,10 +40,10 @@ class DoctrineCloseConnectionMiddleware implements MiddlewareInterface */ public function handle(Envelope $envelope, StackInterface $stack): Envelope { - $entityManager = $this->managerRegistry->getManager($this->entityManagerName); - - if (!$entityManager instanceof EntityManagerInterface) { - throw new \InvalidArgumentException(sprintf('The ObjectManager with name "%s" must be an instance of EntityManagerInterface', $this->entityManagerName)); + try { + $entityManager = $this->managerRegistry->getManager($this->entityManagerName); + } catch (\InvalidArgumentException $e) { + throw new UnrecoverableMessageHandlingException($e->getMessage(), 0, $e); } try { diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php index 021d7a8392..ca9f65d9de 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php @@ -12,8 +12,8 @@ namespace Symfony\Bridge\Doctrine\Messenger; use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Messenger\Envelope; +use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; use Symfony\Component\Messenger\Middleware\StackInterface; @@ -40,10 +40,10 @@ class DoctrinePingConnectionMiddleware implements MiddlewareInterface */ public function handle(Envelope $envelope, StackInterface $stack): Envelope { - $entityManager = $this->managerRegistry->getManager($this->entityManagerName); - - if (!$entityManager instanceof EntityManagerInterface) { - throw new \InvalidArgumentException(sprintf('The ObjectManager with name "%s" must be an instance of EntityManagerInterface', $this->entityManagerName)); + try { + $entityManager = $this->managerRegistry->getManager($this->entityManagerName); + } catch (\InvalidArgumentException $e) { + throw new UnrecoverableMessageHandlingException($e->getMessage(), 0, $e); } $connection = $entityManager->getConnection(); diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php index efab98d54f..0c207567ca 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php @@ -12,8 +12,8 @@ namespace Symfony\Bridge\Doctrine\Messenger; use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Messenger\Envelope; +use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; use Symfony\Component\Messenger\Middleware\StackInterface; @@ -40,10 +40,10 @@ class DoctrineTransactionMiddleware implements MiddlewareInterface */ public function handle(Envelope $envelope, StackInterface $stack): Envelope { - $entityManager = $this->managerRegistry->getManager($this->entityManagerName); - - if (!$entityManager instanceof EntityManagerInterface) { - throw new \InvalidArgumentException(sprintf('The ObjectManager with name "%s" must be an instance of EntityManagerInterface', $this->entityManagerName)); + try { + $entityManager = $this->managerRegistry->getManager($this->entityManagerName); + } catch (\InvalidArgumentException $e) { + throw new UnrecoverableMessageHandlingException($e->getMessage(), 0, $e); } $entityManager->getConnection()->beginTransaction(); diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineCloseConnectionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineCloseConnectionMiddlewareTest.php index 3036b42593..df5414e3cc 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineCloseConnectionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineCloseConnectionMiddlewareTest.php @@ -16,6 +16,7 @@ use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bridge\Doctrine\Messenger\DoctrineCloseConnectionMiddleware; use Symfony\Component\Messenger\Envelope; +use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; use Symfony\Component\Messenger\Test\Middleware\MiddlewareTestCase; class DoctrineCloseConnectionMiddlewareTest extends MiddlewareTestCase @@ -50,4 +51,19 @@ class DoctrineCloseConnectionMiddlewareTest extends MiddlewareTestCase $this->middleware->handle(new Envelope(new \stdClass()), $this->getStackMock()); } + + public function testInvalidEntityManagerThrowsException() + { + $managerRegistry = $this->createMock(ManagerRegistry::class); + $managerRegistry + ->method('getManager') + ->with('unknown_manager') + ->will($this->throwException(new \InvalidArgumentException())); + + $middleware = new DoctrineCloseConnectionMiddleware($managerRegistry, 'unknown_manager'); + + $this->expectException(UnrecoverableMessageHandlingException::class); + + $middleware->handle(new Envelope(new \stdClass()), $this->getStackMock(false)); + } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php index cc15625227..ae71d0d168 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php @@ -16,6 +16,7 @@ use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware; use Symfony\Component\Messenger\Envelope; +use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; use Symfony\Component\Messenger\Test\Middleware\MiddlewareTestCase; class DoctrinePingConnectionMiddlewareTest extends MiddlewareTestCase @@ -71,4 +72,19 @@ class DoctrinePingConnectionMiddlewareTest extends MiddlewareTestCase $this->middleware->handle(new Envelope(new \stdClass()), $this->getStackMock()); } + + public function testInvalidEntityManagerThrowsException() + { + $managerRegistry = $this->createMock(ManagerRegistry::class); + $managerRegistry + ->method('getManager') + ->with('unknown_manager') + ->will($this->throwException(new \InvalidArgumentException())); + + $middleware = new DoctrinePingConnectionMiddleware($managerRegistry, 'unknown_manager'); + + $this->expectException(UnrecoverableMessageHandlingException::class); + + $middleware->handle(new Envelope(new \stdClass()), $this->getStackMock(false)); + } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php index 5927a993d1..04fb86140e 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php @@ -16,6 +16,7 @@ use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware; use Symfony\Component\Messenger\Envelope; +use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException; use Symfony\Component\Messenger\Test\Middleware\MiddlewareTestCase; class DoctrineTransactionMiddlewareTest extends MiddlewareTestCase @@ -67,4 +68,19 @@ class DoctrineTransactionMiddlewareTest extends MiddlewareTestCase $this->middleware->handle(new Envelope(new \stdClass()), $this->getThrowingStackMock()); } + + public function testInvalidEntityManagerThrowsException() + { + $managerRegistry = $this->createMock(ManagerRegistry::class); + $managerRegistry + ->method('getManager') + ->with('unknown_manager') + ->will($this->throwException(new \InvalidArgumentException())); + + $middleware = new DoctrineTransactionMiddleware($managerRegistry, 'unknown_manager'); + + $this->expectException(UnrecoverableMessageHandlingException::class); + + $middleware->handle(new Envelope(new \stdClass()), $this->getStackMock(false)); + } } diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 265994893d..4dfc1ec787 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -29,7 +29,7 @@ "symfony/dependency-injection": "~3.4|~4.0", "symfony/form": "~4.3", "symfony/http-kernel": "~3.4|~4.0", - "symfony/messenger": "~4.2", + "symfony/messenger": "~4.3", "symfony/property-access": "~3.4|~4.0", "symfony/property-info": "~3.4|~4.0", "symfony/proxy-manager-bridge": "~3.4|~4.0", @@ -49,7 +49,7 @@ "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0", "symfony/dependency-injection": "<3.4", "symfony/form": "<4.3", - "symfony/messenger": "<4.2" + "symfony/messenger": "<4.3" }, "suggest": { "symfony/form": "",