12
12
13
13
class JobChainingTest extends TestCase
14
14
{
15
- public static $ catchCallbackRan = false ;
15
+ public static $ catchCallbackCount = 0 ;
16
16
17
17
protected function getEnvironmentSetUp ($ app )
18
18
{
@@ -30,7 +30,6 @@ protected function tearDown(): void
30
30
JobChainingTestFirstJob::$ ran = false ;
31
31
JobChainingTestSecondJob::$ ran = false ;
32
32
JobChainingTestThirdJob::$ ran = false ;
33
- static ::$ catchCallbackRan = false ;
34
33
}
35
34
36
35
public function testJobsCanBeChainedOnSuccess ()
@@ -148,19 +147,56 @@ public function testThirdJobIsNotFiredIfSecondFails()
148
147
149
148
public function testCatchCallbackIsCalledOnFailure ()
150
149
{
150
+ self ::$ catchCallbackCount = 0 ;
151
+
151
152
Bus::chain ([
152
153
new JobChainingTestFirstJob ,
153
154
new JobChainingTestFailingJob ,
154
155
new JobChainingTestSecondJob ,
155
156
])->catch (static function () {
156
- self ::$ catchCallbackRan = true ;
157
+ self ::$ catchCallbackCount ++ ;
157
158
})->dispatch ();
158
159
159
160
$ this ->assertTrue (JobChainingTestFirstJob::$ ran );
160
- $ this ->assertTrue ( static ::$ catchCallbackRan );
161
+ $ this ->assertSame ( 1 , static ::$ catchCallbackCount );
161
162
$ this ->assertFalse (JobChainingTestSecondJob::$ ran );
162
163
}
163
164
165
+ public function testCatchCallbackIsCalledOnceOnSyncQueue ()
166
+ {
167
+ self ::$ catchCallbackCount = 0 ;
168
+
169
+ try {
170
+ Bus::chain ([
171
+ new JobChainingTestFirstJob (),
172
+ new JobChainingTestThrowJob (),
173
+ new JobChainingTestSecondJob (),
174
+ ])->catch (function () {
175
+ self ::$ catchCallbackCount ++;
176
+ })->onConnection ('sync ' )->dispatch ();
177
+ } finally {
178
+ $ this ->assertTrue (JobChainingTestFirstJob::$ ran );
179
+ $ this ->assertSame (1 , static ::$ catchCallbackCount );
180
+ $ this ->assertFalse (JobChainingTestSecondJob::$ ran );
181
+ }
182
+
183
+ self ::$ catchCallbackCount = 0 ;
184
+
185
+ try {
186
+ Bus::chain ([
187
+ new JobChainingTestFirstJob (),
188
+ new JobChainingTestThrowJob (),
189
+ new JobChainingTestSecondJob (),
190
+ ])->catch (function () {
191
+ self ::$ catchCallbackCount ++;
192
+ })->onConnection ('sync ' )->dispatch ();
193
+ } finally {
194
+ $ this ->assertTrue (JobChainingTestFirstJob::$ ran );
195
+ $ this ->assertSame (1 , static ::$ catchCallbackCount );
196
+ $ this ->assertFalse (JobChainingTestSecondJob::$ ran );
197
+ }
198
+ }
199
+
164
200
public function testChainJobsUseSameConfig ()
165
201
{
166
202
JobChainingTestFirstJob::dispatch ()->allOnQueue ('some_queue ' )->allOnConnection ('sync1 ' )->chain ([
@@ -293,3 +329,13 @@ public function handle()
293
329
$ this ->fail ();
294
330
}
295
331
}
332
+
333
+ class JobChainingTestThrowJob implements ShouldQueue
334
+ {
335
+ use Dispatchable, InteractsWithQueue, Queueable;
336
+
337
+ public function handle ()
338
+ {
339
+ throw new \Exception ();
340
+ }
341
+ }
0 commit comments