Add test on nextRunDate in KeyCheckWorker

[MAILPOET-3271]
This commit is contained in:
Jan Lysý
2021-01-14 16:59:43 +01:00
committed by Veljko V
parent 3a7beb6e3f
commit 84f2d5de0b
2 changed files with 30 additions and 3 deletions

View File

@@ -69,6 +69,31 @@ class KeyCheckWorkerTest extends \MailPoetTest {
expect($result)->false(); expect($result)->false();
} }
public function testItNextRunIsNextDay(): void {
$dateTime = Carbon::now();
$wp = Stub::make(new WPFunctions, [
'currentTime' => function($format) use ($dateTime) {
return $dateTime->getTimestamp();
},
]);
$worker = Stub::make(
$this->worker,
[
'checkKey' => ['code' => Bridge::CHECK_ERROR_UNAVAILABLE],
'wp' => $wp,
],
$this
);
/** @var Carbon $nextRunDate */
$nextRunDate = $worker->getNextRunDate();
$secondsToMidnight = $dateTime->diffInSeconds($dateTime->copy()->startOfDay()->addDay());
// next run should be planned in 6 hours after midnight
expect($nextRunDate->diffInSeconds($dateTime))->lessOrEquals(21600 + $secondsToMidnight);
}
private function createRunningTask() { private function createRunningTask() {
$task = ScheduledTask::create(); $task = ScheduledTask::create();
$task->type = MockKeyCheckWorker::TASK_TYPE; $task->type = MockKeyCheckWorker::TASK_TYPE;

View File

@@ -34,9 +34,11 @@ class SendingServiceKeyCheckTest extends \MailPoetTest {
} }
public function testItRunsEveryHourWhenKeyPendingApproval() { public function testItRunsEveryHourWhenKeyPendingApproval() {
// normally next run is scheduled at a start of next day // normally next run is scheduled at the next day in first six hours
expect($this->worker->getNextRunDate()->format('Y-m-d H:i:s')) $nextRun = $this->worker->getNextRunDate();
->equals(Carbon::now()->startOfDay()->addDay()->format('Y-m-d H:i:s')); $nextDay = Carbon::now()->startOfDay()->addDay()->addHours(6);
expect($nextRun->format('Y-m-d'))->equals($nextDay->format('Y-m-d'));
expect($nextRun)->lessThan($nextDay);
// when pending key approval, next run is scheduled in an hour // when pending key approval, next run is scheduled in an hour
$settings = $this->diContainer->get(SettingsController::class); $settings = $this->diContainer->get(SettingsController::class);