From dc83ea157d7ea190e01673ebe3890e36ec7c576c Mon Sep 17 00:00:00 2001 From: Moshe Weitzman Date: Sun, 8 May 2022 06:45:37 -0400 Subject: [PATCH 1/2] Test the finished callback of batch runner. Refs #5009 --- tests/functional/BatchTest.php | 4 +++- tests/unish/Batch/UnitBatchOperations.php | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/functional/BatchTest.php b/tests/functional/BatchTest.php index a546a9d729..3566b3bb1a 100644 --- a/tests/functional/BatchTest.php +++ b/tests/functional/BatchTest.php @@ -16,6 +16,8 @@ public function testBatch() 'include' => __DIR__, ]; $this->drush('unit-batch', [], $options); - $this->assertStringContainsString('!!! ArrayObject does its job.', $this->getErrorOutput()); + $error_output = $this->getErrorOutput(); + $this->assertStringContainsString('!!! ArrayObject does its job.', $error_output); + $this->assertStringContainsString('Result count is 5', $error_output); } } diff --git a/tests/unish/Batch/UnitBatchOperations.php b/tests/unish/Batch/UnitBatchOperations.php index c923b598cf..60142bd41c 100644 --- a/tests/unish/Batch/UnitBatchOperations.php +++ b/tests/unish/Batch/UnitBatchOperations.php @@ -12,13 +12,17 @@ public static function operate(&$context) for ($i = 0; $i < 5; $i++) { Drush::logger()->info("Iteration $i"); + // Store some results for post-processing in the 'finished' callback. + // The contents of 'results' will be available as $results in the + // 'finished' function. + $context['results'][] = $i; + } $context['finished'] = 1; } - public static function finish() + public static function finish($success, $results, $operations) { - // Restore php limits. - // TODO. + Drush::logger()->success("Result count is " . count($results)); } } From 4f5cd065896f312debeb07f71782a1d5b92d9cc2 Mon Sep 17 00:00:00 2001 From: Moshe Weitzman Date: Sun, 8 May 2022 06:50:50 -0400 Subject: [PATCH 2/2] phpcs --- tests/unish/Batch/UnitBatchOperations.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unish/Batch/UnitBatchOperations.php b/tests/unish/Batch/UnitBatchOperations.php index 60142bd41c..2610dfa32a 100644 --- a/tests/unish/Batch/UnitBatchOperations.php +++ b/tests/unish/Batch/UnitBatchOperations.php @@ -16,7 +16,6 @@ public static function operate(&$context) // The contents of 'results' will be available as $results in the // 'finished' function. $context['results'][] = $i; - } $context['finished'] = 1; }