diff --git a/tests/integration/Cron/Workers/KeyCheck/KeyCheckWorkerTest.php b/tests/integration/Cron/Workers/KeyCheck/KeyCheckWorkerTest.php index 942fdc9fb0..79087e71f1 100644 --- a/tests/integration/Cron/Workers/KeyCheck/KeyCheckWorkerTest.php +++ b/tests/integration/Cron/Workers/KeyCheck/KeyCheckWorkerTest.php @@ -69,6 +69,31 @@ class KeyCheckWorkerTest extends \MailPoetTest { 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() { $task = ScheduledTask::create(); $task->type = MockKeyCheckWorker::TASK_TYPE; diff --git a/tests/integration/Cron/Workers/KeyCheck/SendingServiceKeyCheckTest.php b/tests/integration/Cron/Workers/KeyCheck/SendingServiceKeyCheckTest.php index fc8099f078..0f2bb4487c 100644 --- a/tests/integration/Cron/Workers/KeyCheck/SendingServiceKeyCheckTest.php +++ b/tests/integration/Cron/Workers/KeyCheck/SendingServiceKeyCheckTest.php @@ -34,9 +34,11 @@ class SendingServiceKeyCheckTest extends \MailPoetTest { } public function testItRunsEveryHourWhenKeyPendingApproval() { - // normally next run is scheduled at a start of next day - expect($this->worker->getNextRunDate()->format('Y-m-d H:i:s')) - ->equals(Carbon::now()->startOfDay()->addDay()->format('Y-m-d H:i:s')); + // normally next run is scheduled at the next day in first six hours + $nextRun = $this->worker->getNextRunDate(); + $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 $settings = $this->diContainer->get(SettingsController::class);