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 11
11
12
12
namespace Symfony \Bridge \Doctrine \Messenger ;
13
13
14
+ use Doctrine \DBAL \DBALException ;
14
15
use Doctrine \ORM \EntityManagerInterface ;
15
16
use Symfony \Component \Messenger \Envelope ;
16
17
use Symfony \Component \Messenger \Middleware \StackInterface ;
@@ -36,7 +37,9 @@ private function pingConnection(EntityManagerInterface $entityManager)
36
37
{
37
38
$ connection = $ entityManager ->getConnection ();
38
39
39
- if (!$ connection ->ping ()) {
40
+ try {
41
+ $ connection ->query ($ connection ->getDatabasePlatform ()->getDummySelectSQL ());
42
+ } catch (DBALException $ e ) {
40
43
$ connection ->close ();
41
44
$ connection ->connect ();
42
45
}
Original file line number Diff line number Diff line change 12
12
namespace Symfony \Bridge \Doctrine \Tests \Messenger ;
13
13
14
14
use Doctrine \DBAL \Connection ;
15
+ use Doctrine \DBAL \DBALException ;
15
16
use Doctrine \ORM \EntityManagerInterface ;
16
17
use Doctrine \Persistence \ManagerRegistry ;
17
18
use Symfony \Bridge \Doctrine \Messenger \DoctrinePingConnectionMiddleware ;
@@ -47,8 +48,8 @@ protected function setUp(): void
47
48
public function testMiddlewarePingOk ()
48
49
{
49
50
$ this ->connection ->expects ($ this ->once ())
50
- ->method ('ping ' )
51
- ->willReturn ( false );
51
+ ->method ('getDatabasePlatform ' )
52
+ ->will ( $ this -> throwException ( new DBALException ()) );
52
53
53
54
$ this ->connection ->expects ($ this ->once ())
54
55
->method ('close ' )
@@ -65,6 +66,10 @@ public function testMiddlewarePingOk()
65
66
66
67
public function testMiddlewarePingResetEntityManager ()
67
68
{
69
+ $ this ->connection ->expects ($ this ->once ())
70
+ ->method ('getDatabasePlatform ' )
71
+ ->will ($ this ->throwException (new DBALException ()));
72
+
68
73
$ this ->entityManager ->expects ($ this ->once ())
69
74
->method ('isOpen ' )
70
75
->willReturn (false )
You can’t perform that action at this time.
0 commit comments