3
3
namespace Enqueue \Bundle \Tests \Unit \Consumption \Extension ;
4
4
5
5
use Doctrine \DBAL \Connection ;
6
+ use Doctrine \DBAL \Driver \DriverException ;
7
+ use Doctrine \DBAL \Exception \ConnectionLost ;
8
+ use Doctrine \DBAL \Platforms \AbstractPlatform ;
6
9
use Doctrine \Persistence \ManagerRegistry ;
7
10
use Enqueue \Bundle \Consumption \Extension \DoctrinePingConnectionExtension ;
8
11
use Enqueue \Consumption \Context \MessageReceived ;
@@ -29,10 +32,17 @@ public function testShouldNotReconnectIfConnectionIsOK()
29
32
->method ('isConnected ' )
30
33
->willReturn (true )
31
34
;
35
+
36
+ $ abstractPlatform = $ this ->createMock (AbstractPlatform::class);
37
+ $ abstractPlatform ->expects ($ this ->once ())
38
+ ->method ('getDummySelectSQL ' )
39
+ ->willReturn ('dummy ' )
40
+ ;
41
+
32
42
$ connection
33
43
->expects ($ this ->once ())
34
- ->method ('ping ' )
35
- ->willReturn (true )
44
+ ->method ('getDatabasePlatform ' )
45
+ ->willReturn ($ abstractPlatform )
36
46
;
37
47
$ connection
38
48
->expects ($ this ->never ())
@@ -70,8 +80,8 @@ public function testShouldDoesReconnectIfConnectionFailed()
70
80
;
71
81
$ connection
72
82
->expects ($ this ->once ())
73
- ->method ('ping ' )
74
- ->willReturn ( false )
83
+ ->method ('getDatabasePlatform ' )
84
+ ->willThrowException ( new ConnectionLost ( ' message ' , $ this -> createMock (DriverException::class)) )
75
85
;
76
86
$ connection
77
87
->expects ($ this ->once ())
@@ -128,10 +138,16 @@ public function testShouldSkipIfConnectionWasNotOpened()
128
138
->method ('isConnected ' )
129
139
->willReturn (true )
130
140
;
141
+ $ abstractPlatform = $ this ->createMock (AbstractPlatform::class);
142
+ $ abstractPlatform ->expects ($ this ->once ())
143
+ ->method ('getDummySelectSQL ' )
144
+ ->willReturn ('dummy ' )
145
+ ;
146
+
131
147
$ connection2
132
148
->expects ($ this ->once ())
133
- ->method ('ping ' )
134
- ->willReturn (true )
149
+ ->method ('getDatabasePlatform ' )
150
+ ->willReturn ($ abstractPlatform )
135
151
;
136
152
137
153
$ context = $ this ->createContext ();
0 commit comments