@@ -35,6 +35,51 @@ public function testShouldCreateJobObject()
3535 ->with ('entity-class ' )
3636 ->will ($ this ->returnValue ($ repository ))
3737 ;
38+ $ em
39+ ->expects ($ this ->any ())
40+ ->method ('isOpen ' )
41+ ->will ($ this ->returnValue (true ))
42+ ;
43+
44+ $ doctrine = $ this ->createDoctrineMock ();
45+ $ doctrine
46+ ->expects ($ this ->once ())
47+ ->method ('getManagerForClass ' )
48+ ->with ('entity-class ' )
49+ ->will ($ this ->returnValue ($ em ))
50+ ;
51+ $ doctrine
52+ ->expects ($ this ->never ())
53+ ->method ('resetManager ' )
54+ ;
55+
56+ $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
57+ $ job = $ storage ->createJob ();
58+
59+ $ this ->assertInstanceOf (Job::class, $ job );
60+ }
61+
62+ public function testShouldResetManagerAndCreateJobObject ()
63+ {
64+ $ repository = $ this ->createRepositoryMock ();
65+ $ repository
66+ ->expects ($ this ->once ())
67+ ->method ('getClassName ' )
68+ ->will ($ this ->returnValue (Job::class))
69+ ;
70+
71+ $ em = $ this ->createEntityManagerMock ();
72+ $ em
73+ ->expects ($ this ->once ())
74+ ->method ('getRepository ' )
75+ ->with ('entity-class ' )
76+ ->will ($ this ->returnValue ($ repository ))
77+ ;
78+ $ em
79+ ->expects ($ this ->any ())
80+ ->method ('isOpen ' )
81+ ->will ($ this ->returnValue (false ))
82+ ;
3883
3984 $ doctrine = $ this ->createDoctrineMock ();
4085 $ doctrine
@@ -43,6 +88,11 @@ public function testShouldCreateJobObject()
4388 ->with ('entity-class ' )
4489 ->will ($ this ->returnValue ($ em ))
4590 ;
91+ $ doctrine
92+ ->expects ($ this ->any ())
93+ ->method ('resetManager ' )
94+ ->will ($ this ->returnValue ($ em ))
95+ ;
4696
4797 $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
4898 $ job = $ storage ->createJob ();
@@ -66,6 +116,11 @@ public function testShouldThrowIfGotUnexpectedJobInstance()
66116 ->with ('entity-class ' )
67117 ->will ($ this ->returnValue ($ repository ))
68118 ;
119+ $ em
120+ ->expects ($ this ->any ())
121+ ->method ('isOpen ' )
122+ ->will ($ this ->returnValue (true ))
123+ ;
69124
70125 $ doctrine = $ this ->createDoctrineMock ();
71126 $ doctrine
@@ -74,6 +129,10 @@ public function testShouldThrowIfGotUnexpectedJobInstance()
74129 ->with ('entity-class ' )
75130 ->will ($ this ->returnValue ($ em ))
76131 ;
132+ $ doctrine
133+ ->expects ($ this ->never ())
134+ ->method ('resetManager ' )
135+ ;
77136
78137 $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
79138
@@ -120,6 +179,11 @@ public function testShouldSaveJobWithoutLockIfThereIsNoCallbackAndChildJob()
120179 ->expects ($ this ->never ())
121180 ->method ('transactional ' )
122181 ;
182+ $ em
183+ ->expects ($ this ->any ())
184+ ->method ('isOpen ' )
185+ ->will ($ this ->returnValue (true ))
186+ ;
123187
124188 $ doctrine = $ this ->createDoctrineMock ();
125189 $ doctrine
@@ -128,6 +192,10 @@ public function testShouldSaveJobWithoutLockIfThereIsNoCallbackAndChildJob()
128192 ->with ('entity-class ' )
129193 ->will ($ this ->returnValue ($ em ))
130194 ;
195+ $ doctrine
196+ ->expects ($ this ->never ())
197+ ->method ('resetManager ' )
198+ ;
131199
132200 $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
133201 $ storage ->saveJob ($ child );
@@ -165,6 +233,11 @@ public function testShouldSaveJobWithLockIfWithCallback()
165233 ->expects ($ this ->once ())
166234 ->method ('transactional ' )
167235 ;
236+ $ em
237+ ->expects ($ this ->any ())
238+ ->method ('isOpen ' )
239+ ->will ($ this ->returnValue (true ))
240+ ;
168241
169242 $ doctrine = $ this ->createDoctrineMock ();
170243 $ doctrine
@@ -173,6 +246,10 @@ public function testShouldSaveJobWithLockIfWithCallback()
173246 ->with ('entity-class ' )
174247 ->will ($ this ->returnValue ($ em ))
175248 ;
249+ $ doctrine
250+ ->expects ($ this ->never ())
251+ ->method ('resetManager ' )
252+ ;
176253
177254 $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
178255 $ storage ->saveJob ($ job , function () {
@@ -219,6 +296,11 @@ public function testShouldCatchUniqueConstraintViolationExceptionAndThrowDuplica
219296 ->method ('getConnection ' )
220297 ->will ($ this ->returnValue ($ connection ))
221298 ;
299+ $ em
300+ ->expects ($ this ->any ())
301+ ->method ('isOpen ' )
302+ ->will ($ this ->returnValue (true ))
303+ ;
222304
223305 $ doctrine = $ this ->createDoctrineMock ();
224306 $ doctrine
@@ -227,6 +309,10 @@ public function testShouldCatchUniqueConstraintViolationExceptionAndThrowDuplica
227309 ->with ('entity-class ' )
228310 ->will ($ this ->returnValue ($ em ))
229311 ;
312+ $ doctrine
313+ ->expects ($ this ->never ())
314+ ->method ('resetManager ' )
315+ ;
230316
231317 $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
232318
@@ -253,6 +339,11 @@ public function testShouldThrowIfTryToSaveNewEntityWithLock()
253339 ->with ('entity-class ' )
254340 ->will ($ this ->returnValue ($ repository ))
255341 ;
342+ $ em
343+ ->expects ($ this ->any ())
344+ ->method ('isOpen ' )
345+ ->will ($ this ->returnValue (true ))
346+ ;
256347
257348 $ doctrine = $ this ->createDoctrineMock ();
258349 $ doctrine
@@ -261,6 +352,10 @@ public function testShouldThrowIfTryToSaveNewEntityWithLock()
261352 ->with ('entity-class ' )
262353 ->will ($ this ->returnValue ($ em ))
263354 ;
355+ $ doctrine
356+ ->expects ($ this ->never ())
357+ ->method ('resetManager ' )
358+ ;
264359
265360 $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
266361
@@ -306,6 +401,11 @@ public function testShouldLockEntityAndPassNewInstanceIntoCallback()
306401 $ callback ($ em );
307402 }))
308403 ;
404+ $ em
405+ ->expects ($ this ->any ())
406+ ->method ('isOpen ' )
407+ ->will ($ this ->returnValue (true ))
408+ ;
309409
310410 $ doctrine = $ this ->createDoctrineMock ();
311411 $ doctrine
@@ -314,6 +414,10 @@ public function testShouldLockEntityAndPassNewInstanceIntoCallback()
314414 ->with ('entity-class ' )
315415 ->will ($ this ->returnValue ($ em ))
316416 ;
417+ $ doctrine
418+ ->expects ($ this ->never ())
419+ ->method ('resetManager ' )
420+ ;
317421
318422 $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
319423 $ resultJob = null ;
@@ -377,6 +481,11 @@ public function testShouldInsertIntoUniqueTableIfJobIsUniqueAndNew()
377481 ->expects ($ this ->once ())
378482 ->method ('flush ' )
379483 ;
484+ $ em
485+ ->expects ($ this ->any ())
486+ ->method ('isOpen ' )
487+ ->will ($ this ->returnValue (true ))
488+ ;
380489
381490 $ doctrine = $ this ->createDoctrineMock ();
382491 $ doctrine
@@ -385,6 +494,10 @@ public function testShouldInsertIntoUniqueTableIfJobIsUniqueAndNew()
385494 ->with ('entity-class ' )
386495 ->will ($ this ->returnValue ($ em ))
387496 ;
497+ $ doctrine
498+ ->expects ($ this ->never ())
499+ ->method ('resetManager ' )
500+ ;
388501
389502 $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
390503 $ storage ->saveJob ($ job );
@@ -442,6 +555,11 @@ public function testShouldDeleteRecordFromUniqueTableIfJobIsUniqueAndStoppedAtIs
442555 ->method ('getConnection ' )
443556 ->will ($ this ->returnValue ($ connection ))
444557 ;
558+ $ em
559+ ->expects ($ this ->any ())
560+ ->method ('isOpen ' )
561+ ->will ($ this ->returnValue (true ))
562+ ;
445563
446564 $ doctrine = $ this ->createDoctrineMock ();
447565 $ doctrine
@@ -450,6 +568,10 @@ public function testShouldDeleteRecordFromUniqueTableIfJobIsUniqueAndStoppedAtIs
450568 ->with ('entity-class ' )
451569 ->will ($ this ->returnValue ($ em ))
452570 ;
571+ $ doctrine
572+ ->expects ($ this ->never ())
573+ ->method ('resetManager ' )
574+ ;
453575
454576 $ storage = new JobStorage ($ doctrine , 'entity-class ' , 'unique_table ' );
455577 $ storage ->saveJob ($ job , function () {
0 commit comments