From 9ccf043c7cff0d58547fd25c41a5005fffd7ad72 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 28 Jun 2020 16:40:16 +0200 Subject: [PATCH] [DoctrineBridge] work around Connection::ping() deprecation --- .../Messenger/DoctrinePingConnectionMiddleware.php | 5 ++++- .../Messenger/DoctrinePingConnectionMiddlewareTest.php | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php index f6febb2a7e673..3ec525d2cfd41 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\Doctrine\Messenger; +use Doctrine\DBAL\DBALException; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Middleware\StackInterface; @@ -36,7 +37,9 @@ private function pingConnection(EntityManagerInterface $entityManager) { $connection = $entityManager->getConnection(); - if (!$connection->ping()) { + try { + $connection->query($connection->getDatabasePlatform()->getDummySelectSQL()); + } catch (DBALException $e) { $connection->close(); $connection->connect(); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php index a0932371dfbfd..e491558a2addf 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Messenger; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware; @@ -47,8 +48,8 @@ protected function setUp(): void public function testMiddlewarePingOk() { $this->connection->expects($this->once()) - ->method('ping') - ->willReturn(false); + ->method('getDatabasePlatform') + ->will($this->throwException(new DBALException())); $this->connection->expects($this->once()) ->method('close') @@ -65,6 +66,10 @@ public function testMiddlewarePingOk() public function testMiddlewarePingResetEntityManager() { + $this->connection->expects($this->once()) + ->method('getDatabasePlatform') + ->will($this->throwException(new DBALException())); + $this->entityManager->expects($this->once()) ->method('isOpen') ->willReturn(false) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy