Skip to content

Commit

Permalink
Test the finished callback of batch runner. Refs #5009 (#5144)
Browse files Browse the repository at this point in the history
* Test the finished callback of batch runner. Refs #5009

* phpcs
  • Loading branch information
weitzman committed May 8, 2022
1 parent a4e57fe commit d6d0551
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tests/functional/BatchTest.php
Expand Up @@ -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);
}
}
9 changes: 6 additions & 3 deletions tests/unish/Batch/UnitBatchOperations.php
Expand Up @@ -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));
}
}

0 comments on commit d6d0551

Please sign in to comment.