File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change 1111
1212namespace Symfony \Bridge \Doctrine \Messenger ;
1313
14+ use Doctrine \DBAL \DBALException ;
1415use Doctrine \ORM \EntityManagerInterface ;
1516use Symfony \Component \Messenger \Envelope ;
1617use 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 }
Original file line number Diff line number Diff line change 1212namespace Symfony \Bridge \Doctrine \Tests \Messenger ;
1313
1414use Doctrine \DBAL \Connection ;
15+ use Doctrine \DBAL \DBALException ;
1516use Doctrine \ORM \EntityManagerInterface ;
1617use Doctrine \Persistence \ManagerRegistry ;
1718use 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 )
You can’t perform that action at this time.
0 commit comments