From d6d05512b32ea4dd4983e40b0e0a6e30236050f2 Mon Sep 17 00:00:00 2001 From: Moshe Weitzman Date: Sun, 8 May 2022 07:14:14 -0400 Subject: [PATCH] Test the finished callback of batch runner. Refs #5009 (#5144) * Test the finished callback of batch runner. Refs #5009 * phpcs --- tests/functional/BatchTest.php | 4 +++- tests/unish/Batch/UnitBatchOperations.php | 9 ++++++--- 2 files changed, 9 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..2610dfa32a 100644 --- a/tests/unish/Batch/UnitBatchOperations.php +++ b/tests/unish/Batch/UnitBatchOperations.php @@ -12,13 +12,16 @@ 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)); } }