Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the finished callback of batch runner. Refs #5009 #5144

Merged
merged 2 commits into from May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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));
}
}