[DoctrineBridge] work around Connection::ping() deprecation
This commit is contained in:
parent
36538369ca
commit
9ccf043c7c
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Bridge\Doctrine\Messenger;
|
namespace Symfony\Bridge\Doctrine\Messenger;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\DBALException;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\Messenger\Envelope;
|
use Symfony\Component\Messenger\Envelope;
|
||||||
use Symfony\Component\Messenger\Middleware\StackInterface;
|
use Symfony\Component\Messenger\Middleware\StackInterface;
|
||||||
@ -36,7 +37,9 @@ class DoctrinePingConnectionMiddleware extends AbstractDoctrineMiddleware
|
|||||||
{
|
{
|
||||||
$connection = $entityManager->getConnection();
|
$connection = $entityManager->getConnection();
|
||||||
|
|
||||||
if (!$connection->ping()) {
|
try {
|
||||||
|
$connection->query($connection->getDatabasePlatform()->getDummySelectSQL());
|
||||||
|
} catch (DBALException $e) {
|
||||||
$connection->close();
|
$connection->close();
|
||||||
$connection->connect();
|
$connection->connect();
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Bridge\Doctrine\Tests\Messenger;
|
namespace Symfony\Bridge\Doctrine\Tests\Messenger;
|
||||||
|
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
|
use Doctrine\DBAL\DBALException;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware;
|
use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware;
|
||||||
@ -47,8 +48,8 @@ class DoctrinePingConnectionMiddlewareTest extends MiddlewareTestCase
|
|||||||
public function testMiddlewarePingOk()
|
public function testMiddlewarePingOk()
|
||||||
{
|
{
|
||||||
$this->connection->expects($this->once())
|
$this->connection->expects($this->once())
|
||||||
->method('ping')
|
->method('getDatabasePlatform')
|
||||||
->willReturn(false);
|
->will($this->throwException(new DBALException()));
|
||||||
|
|
||||||
$this->connection->expects($this->once())
|
$this->connection->expects($this->once())
|
||||||
->method('close')
|
->method('close')
|
||||||
@ -65,6 +66,10 @@ class DoctrinePingConnectionMiddlewareTest extends MiddlewareTestCase
|
|||||||
|
|
||||||
public function testMiddlewarePingResetEntityManager()
|
public function testMiddlewarePingResetEntityManager()
|
||||||
{
|
{
|
||||||
|
$this->connection->expects($this->once())
|
||||||
|
->method('getDatabasePlatform')
|
||||||
|
->will($this->throwException(new DBALException()));
|
||||||
|
|
||||||
$this->entityManager->expects($this->once())
|
$this->entityManager->expects($this->once())
|
||||||
->method('isOpen')
|
->method('isOpen')
|
||||||
->willReturn(false)
|
->willReturn(false)
|
||||||
|
Reference in New Issue
Block a user