Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9ccf043

Browse filesBrowse files
[DoctrineBridge] work around Connection::ping() deprecation
1 parent 3653836 commit 9ccf043
Copy full SHA for 9ccf043

File tree

2 files changed

+11
-3
lines changed
Filter options

2 files changed

+11
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php
+4-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php
+7-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.