Skip to content

Commit 9c6d53a

Browse files
bug #37441 [DoctrineBridge] work around Connection::ping() deprecation (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [DoctrineBridge] work around Connection::ping() deprecation | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Follows doctrine/dbal@e603a2e Commits ------- 9ccf043 [DoctrineBridge] work around Connection::ping() deprecation
2 parents 2e2fac8 + 9ccf043 commit 9c6d53a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Messenger;
1313

14+
use Doctrine\DBAL\DBALException;
1415
use Doctrine\ORM\EntityManagerInterface;
1516
use Symfony\Component\Messenger\Envelope;
1617
use Symfony\Component\Messenger\Middleware\StackInterface;
@@ -36,7 +37,9 @@ private function pingConnection(EntityManagerInterface $entityManager)
3637
{
3738
$connection = $entityManager->getConnection();
3839

39-
if (!$connection->ping()) {
40+
try {
41+
$connection->query($connection->getDatabasePlatform()->getDummySelectSQL());
42+
} catch (DBALException $e) {
4043
$connection->close();
4144
$connection->connect();
4245
}

src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Tests\Messenger;
1313

1414
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\DBALException;
1516
use Doctrine\ORM\EntityManagerInterface;
1617
use Doctrine\Persistence\ManagerRegistry;
1718
use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware;
@@ -47,8 +48,8 @@ protected function setUp(): void
4748
public function testMiddlewarePingOk()
4849
{
4950
$this->connection->expects($this->once())
50-
->method('ping')
51-
->willReturn(false);
51+
->method('getDatabasePlatform')
52+
->will($this->throwException(new DBALException()));
5253

5354
$this->connection->expects($this->once())
5455
->method('close')
@@ -65,6 +66,10 @@ public function testMiddlewarePingOk()
6566

6667
public function testMiddlewarePingResetEntityManager()
6768
{
69+
$this->connection->expects($this->once())
70+
->method('getDatabasePlatform')
71+
->will($this->throwException(new DBALException()));
72+
6873
$this->entityManager->expects($this->once())
6974
->method('isOpen')
7075
->willReturn(false)

0 commit comments

Comments
 (0)
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