Skip to content

Commit

Permalink
Test the finished callback of batch runner. Refs drush-ops#5009
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed May 8, 2022
1 parent a4e57fe commit dc83ea1
Show file tree
Hide file tree
Showing 2 changed files with 10 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);
}
}
10 changes: 7 additions & 3 deletions tests/unish/Batch/UnitBatchOperations.php
Expand Up @@ -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));
}
}

0 comments on commit dc83ea1

Please sign in to comment.