public function TaskRunnerTest::testGetPendingTasks in Webform Scheduled Tasks 8.2
@covers ::getPendingTasks
File
- tests/
src/ Kernel/ TaskRunnerTest.php, line 69
Class
- TaskRunnerTest
- @coversDefaultClass \Drupal\webform_scheduled_tasks\TaskRunner @group webform_scheduled_tasks
Namespace
Drupal\Tests\webform_scheduled_tasks\KernelCode
public function testGetPendingTasks() {
$expected_not_pending_tasks = [];
$expected_pending_tasks = [];
// A task with no interval data set, will never be pending.
$expected_not_pending_tasks[] = $this
->createTestTask();
// A task with a run date 5 seconds in the future is not pending.
$expected_not_pending_tasks[] = $this
->createTestTask([
'interval' => [
'amount' => 1,
'multiplier' => 60,
],
])
->setNextTaskRunDate(1005);
// A task with a run date in the past, but no interval information will not
// be a pending task. This is an invalid entity state since the run date
// should be calculated based on the interval.
$expected_not_pending_tasks[] = $this
->createTestTask()
->setNextTaskRunDate(995);
// A task with an interval set, but no run date will default to the current
// time + the interval, meaning it will not currently be pending.
$expected_not_pending_tasks[] = $this
->createTestTask([
'interval' => [
'amount' => 1,
'multiplier' => 60,
],
]);
// Create a task which is ready to run, but is simple halted.
$expected_not_pending_tasks[] = $this
->createTestTask([
'interval' => [
'amount' => 1,
'multiplier' => 60,
],
])
->setNextTaskRunDate(995)
->halt('Something was wrong!');
// A task with an interval and a run date that was 5 seconds in the past
// will be pending execution.
$expected_pending_tasks[] = $this
->createTestTask([
'interval' => [
'amount' => 1,
'multiplier' => 60,
],
])
->setNextTaskRunDate(995);
$pending_tasks = $this->taskRunner
->getPendingTasks();
$id = function (WebformScheduledTaskInterface $task) {
return $task
->id();
};
$this
->assertEquals(array_map($id, $expected_pending_tasks), array_map($id, $pending_tasks));
}