@@ -40,6 +40,7 @@ protected function setUp(): void
40
40
$ this ->createSchema ();
41
41
42
42
$ _SERVER ['__finally.count ' ] = 0 ;
43
+ $ _SERVER ['__progress.count ' ] = 0 ;
43
44
$ _SERVER ['__then.count ' ] = 0 ;
44
45
$ _SERVER ['__catch.count ' ] = 0 ;
45
46
}
@@ -72,7 +73,7 @@ public function createSchema()
72
73
*/
73
74
protected function tearDown (): void
74
75
{
75
- unset($ _SERVER ['__finally.batch ' ], $ _SERVER ['__then.batch ' ], $ _SERVER ['__catch.batch ' ], $ _SERVER ['__catch.exception ' ]);
76
+ unset($ _SERVER ['__finally.batch ' ], $ _SERVER ['__progress.batch ' ], $ _SERVER [ ' __then.batch ' ], $ _SERVER ['__catch.batch ' ], $ _SERVER ['__catch.exception ' ]);
76
77
77
78
$ this ->schema ()->drop ('job_batches ' );
78
79
@@ -201,12 +202,14 @@ public function test_successful_jobs_can_be_recorded()
201
202
$ batch ->recordSuccessfulJob ('test-id ' );
202
203
203
204
$ this ->assertInstanceOf (Batch::class, $ _SERVER ['__finally.batch ' ]);
205
+ $ this ->assertInstanceOf (Batch::class, $ _SERVER ['__progress.batch ' ]);
204
206
$ this ->assertInstanceOf (Batch::class, $ _SERVER ['__then.batch ' ]);
205
207
206
208
$ batch = $ batch ->fresh ();
207
209
$ this ->assertEquals (0 , $ batch ->pendingJobs );
208
210
$ this ->assertTrue ($ batch ->finished ());
209
211
$ this ->assertEquals (1 , $ _SERVER ['__finally.count ' ]);
212
+ $ this ->assertEquals (2 , $ _SERVER ['__progress.count ' ]);
210
213
$ this ->assertEquals (1 , $ _SERVER ['__then.count ' ]);
211
214
}
212
215
@@ -247,6 +250,7 @@ public function test_failed_jobs_can_be_recorded_while_not_allowing_failures()
247
250
$ this ->assertTrue ($ batch ->finished ());
248
251
$ this ->assertTrue ($ batch ->cancelled ());
249
252
$ this ->assertEquals (1 , $ _SERVER ['__finally.count ' ]);
253
+ $ this ->assertEquals (0 , $ _SERVER ['__progress.count ' ]);
250
254
$ this ->assertEquals (1 , $ _SERVER ['__catch.count ' ]);
251
255
$ this ->assertSame ('Something went wrong. ' , $ _SERVER ['__catch.exception ' ]->getMessage ());
252
256
}
@@ -288,6 +292,7 @@ public function test_failed_jobs_can_be_recorded_while_allowing_failures()
288
292
$ this ->assertFalse ($ batch ->finished ());
289
293
$ this ->assertFalse ($ batch ->cancelled ());
290
294
$ this ->assertEquals (1 , $ _SERVER ['__catch.count ' ]);
295
+ $ this ->assertEquals (2 , $ _SERVER ['__progress.count ' ]);
291
296
$ this ->assertSame ('Something went wrong. ' , $ _SERVER ['__catch.exception ' ]->getMessage ());
292
297
}
293
298
@@ -327,6 +332,11 @@ public function test_batch_state_can_be_inspected()
327
332
$ batch ->finishedAt = now ();
328
333
$ this ->assertTrue ($ batch ->finished ());
329
334
335
+ $ batch ->options ['progress ' ] = [];
336
+ $ this ->assertFalse ($ batch ->hasProgressCallbacks ());
337
+ $ batch ->options ['progress ' ] = [1 ];
338
+ $ this ->assertTrue ($ batch ->hasProgressCallbacks ());
339
+
330
340
$ batch ->options ['then ' ] = [];
331
341
$ this ->assertFalse ($ batch ->hasThenCallbacks ());
332
342
$ batch ->options ['then ' ] = [1 ];
@@ -463,6 +473,10 @@ protected function createTestBatch($queue, $allowFailures = false)
463
473
$ repository = new DatabaseBatchRepository (new BatchFactory ($ queue ), DB ::connection (), 'job_batches ' );
464
474
465
475
$ pendingBatch = (new PendingBatch (new Container , collect ()))
476
+ ->progress (function (Batch $ batch ) {
477
+ $ _SERVER ['__progress.batch ' ] = $ batch ;
478
+ $ _SERVER ['__progress.count ' ]++;
479
+ })
466
480
->then (function (Batch $ batch ) {
467
481
$ _SERVER ['__then.batch ' ] = $ batch ;
468
482
$ _SERVER ['__then.count ' ]++;
0 commit comments