@@ -22,6 +22,11 @@ public function testCouldBeConstructedWithRequiredAttributes()
22
22
public function testShouldNotReconnectIfConnectionIsOK ()
23
23
{
24
24
$ connection = $ this ->createConnectionMock ();
25
+ $ connection
26
+ ->expects ($ this ->once ())
27
+ ->method ('isConnected ' )
28
+ ->will ($ this ->returnValue (true ))
29
+ ;
25
30
$ connection
26
31
->expects ($ this ->once ())
27
32
->method ('ping ' )
@@ -56,6 +61,11 @@ public function testShouldNotReconnectIfConnectionIsOK()
56
61
public function testShouldDoesReconnectIfConnectionFailed ()
57
62
{
58
63
$ connection = $ this ->createConnectionMock ();
64
+ $ connection
65
+ ->expects ($ this ->once ())
66
+ ->method ('isConnected ' )
67
+ ->will ($ this ->returnValue (true ))
68
+ ;
59
69
$ connection
60
70
->expects ($ this ->once ())
61
71
->method ('ping ' )
@@ -93,6 +103,49 @@ public function testShouldDoesReconnectIfConnectionFailed()
93
103
$ extension ->onPreReceived ($ context );
94
104
}
95
105
106
+ public function testShouldSkipIfConnectionWasNotOpened ()
107
+ {
108
+ $ connection1 = $ this ->createConnectionMock ();
109
+ $ connection1
110
+ ->expects ($ this ->once ())
111
+ ->method ('isConnected ' )
112
+ ->will ($ this ->returnValue (false ))
113
+ ;
114
+ $ connection1
115
+ ->expects ($ this ->never ())
116
+ ->method ('ping ' )
117
+ ;
118
+
119
+ // 2nd connection was opened in the past
120
+ $ connection2 = $ this ->createConnectionMock ();
121
+ $ connection2
122
+ ->expects ($ this ->once ())
123
+ ->method ('isConnected ' )
124
+ ->will ($ this ->returnValue (true ))
125
+ ;
126
+ $ connection2
127
+ ->expects ($ this ->once ())
128
+ ->method ('ping ' )
129
+ ->will ($ this ->returnValue (true ))
130
+ ;
131
+
132
+ $ context = $ this ->createPsrContext ();
133
+ $ context ->getLogger ()
134
+ ->expects ($ this ->never ())
135
+ ->method ('debug ' )
136
+ ;
137
+
138
+ $ registry = $ this ->createRegistryMock ();
139
+ $ registry
140
+ ->expects ($ this ->once ())
141
+ ->method ('getConnections ' )
142
+ ->will ($ this ->returnValue ([$ connection1 , $ connection2 ]))
143
+ ;
144
+
145
+ $ extension = new DoctrinePingConnectionExtension ($ registry );
146
+ $ extension ->onPreReceived ($ context );
147
+ }
148
+
96
149
/**
97
150
* @return Context
98
151
*/
0 commit comments