@@ -120,6 +120,76 @@ public function testMiddlewareNoPingInNonWorkerContext()
120120$ this ->middleware ->handle ($ envelope ,$ this ->getStackMock ());
121121 }
122122
123+ public function testMiddlewarePingsAllConnectionsWhenEntityManagerNameIsNull ()
124+ {
125+ $ firstConnection =$ this ->createMock (Connection::class);
126+ $ firstConnection ->method ('getDatabasePlatform ' )->willReturn ($ this ->mockPlatform ());
127+ $ firstConnection ->expects ($ this ->once ())->method ('executeQuery ' );
128+
129+ $ secondConnection =$ this ->createMock (Connection::class);
130+ $ secondConnection ->method ('getDatabasePlatform ' )->willReturn ($ this ->mockPlatform ());
131+ $ secondConnection ->expects ($ this ->once ())->method ('executeQuery ' );
132+
133+ $ firstManager =$ this ->createMock (EntityManagerInterface::class);
134+ $ firstManager ->method ('getConnection ' )->willReturn ($ firstConnection );
135+
136+ $ secondManager =$ this ->createMock (EntityManagerInterface::class);
137+ $ secondManager ->method ('getConnection ' )->willReturn ($ secondConnection );
138+
139+ $ managerRegistry =$ this ->createMock (ManagerRegistry::class);
140+ $ managerRegistry ->method ('getManager ' )->with (null )->willReturn ($ firstManager );
141+ $ managerRegistry ->method ('getManagers ' )->willReturn ([
142+ 'first ' =>$ firstManager ,
143+ 'second ' =>$ secondManager ,
144+ ]);
145+
146+ $ middleware =new DoctrinePingConnectionMiddleware ($ managerRegistry );
147+
148+ $ envelope =new Envelope (new \stdClass (), [
149+ new ConsumedByWorkerStamp (),
150+ ]);
151+ $ middleware ->handle ($ envelope ,$ this ->getStackMock ());
152+ }
153+
154+ public function testMiddlewareResetsClosedManagersWhenEntityManagerNameIsNull ()
155+ {
156+ $ platform =$ this ->mockPlatform ();
157+
158+ $ openConnection =$ this ->createMock (Connection::class);
159+ $ openConnection ->method ('getDatabasePlatform ' )->willReturn ($ platform );
160+ $ openConnection ->expects ($ this ->once ())->method ('executeQuery ' );
161+
162+ $ closedConnection =$ this ->createMock (Connection::class);
163+ $ closedConnection ->method ('getDatabasePlatform ' )->willReturn ($ platform );
164+ $ closedConnection ->expects ($ this ->once ())->method ('executeQuery ' );
165+
166+ $ openManager =$ this ->createMock (EntityManagerInterface::class);
167+ $ openManager ->method ('getConnection ' )->willReturn ($ openConnection );
168+ $ openManager ->expects ($ this ->once ())->method ('isOpen ' )->willReturn (true );
169+
170+ $ closedManager =$ this ->createMock (EntityManagerInterface::class);
171+ $ closedManager ->method ('getConnection ' )->willReturn ($ closedConnection );
172+ $ closedManager ->expects ($ this ->once ())->method ('isOpen ' )->willReturn (false );
173+
174+ $ managerRegistry =$ this ->createMock (ManagerRegistry::class);
175+ $ managerRegistry ->method ('getManager ' )->with (null )->willReturn ($ openManager );
176+ $ managerRegistry ->method ('getManagers ' )->willReturn ([
177+ 'open ' =>$ openManager ,
178+ 'closed ' =>$ closedManager ,
179+ ]);
180+ $ managerRegistry ->expects ($ this ->once ())
181+ ->method ('resetManager ' )
182+ ->with ('closed ' )
183+ ;
184+
185+ $ middleware =new DoctrinePingConnectionMiddleware ($ managerRegistry );
186+
187+ $ envelope =new Envelope (new \stdClass (), [
188+ new ConsumedByWorkerStamp (),
189+ ]);
190+ $ middleware ->handle ($ envelope ,$ this ->getStackMock ());
191+ }
192+
123193private function mockPlatform ():AbstractPlatform &MockObject
124194 {
125195$ platform =$ this ->createMock (AbstractPlatform::class);