Improve readability of scheduler code

[MAILPOET-6142]
This commit is contained in:
Rostislav Wolny
2024-08-13 14:36:05 +02:00
committed by Aschepikov
parent 07221d9c68
commit bb7ab59ed5
4 changed files with 30 additions and 21 deletions

View File

@@ -52,8 +52,9 @@ class SchedulerTest extends \MailPoetTest {
public function testItCanGetCorrectNextRunDateInGMTTimezone() {
$currentTime = '2024-08-09 09:00:00';
$wpMock = $this->createMock(WPFunctions::class);
$wpMock->method('currentTime')->willReturn(strtotime($currentTime));
$wpMock->method('wpTimezone')->willReturn(new \DateTimeZone('UTC'));
$wpMock->method('currentDatetime')->willReturn(
new \DateTimeImmutable($currentTime, new \DateTimeZone('UTC')),
);
$scheduler = $this->getServiceWithOverrides(Scheduler::class, ['wp' => $wpMock]);
verify($scheduler->getNextRunDate('0 10 * * *'))
->equals('2024-08-09 10:00:00');
@@ -62,8 +63,9 @@ class SchedulerTest extends \MailPoetTest {
public function testItCanGetCorrectNextRunDateInNewYorkTimezone() {
$currentTime = '2024-08-09 09:00:00';
$wpMock = $this->createMock(WPFunctions::class);
$wpMock->method('currentTime')->willReturn(strtotime($currentTime));
$wpMock->method('wpTimezone')->willReturn(new \DateTimeZone('America/New_York'));
$wpMock->method('currentDatetime')->willReturn(
new \DateTimeImmutable($currentTime, new \DateTimeZone('America/New_York'))
);
$scheduler = $this->getServiceWithOverrides(Scheduler::class, ['wp' => $wpMock]);
// Cron was set by user in NewYork timezone (0 10 * * *) in UTC it would be (0 14 * * *)
verify($scheduler->getNextRunDate('0 10 * * *'))
@@ -83,8 +85,9 @@ class SchedulerTest extends \MailPoetTest {
public function testItCanGetCorrectPreviousRunDateInGMTTimezone() {
$currentTime = '2024-08-09 09:00:00';
$wpMock = $this->createMock(WPFunctions::class);
$wpMock->method('currentTime')->willReturn(strtotime($currentTime));
$wpMock->method('wpTimezone')->willReturn(new \DateTimeZone('UTC'));
$wpMock->method('currentDatetime')->willReturn(
new \DateTimeImmutable($currentTime, new \DateTimeZone('UTC'))
);
$scheduler = $this->getServiceWithOverrides(Scheduler::class, ['wp' => $wpMock]);
verify($scheduler->getPreviousRunDate('0 10 * * *'))
->equals('2024-08-08 10:00:00');
@@ -93,8 +96,9 @@ class SchedulerTest extends \MailPoetTest {
public function testItCanGetCorrectPreviousRunDateInNewYorkTimezone() {
$currentTime = '2024-08-09 09:00:00';
$wpMock = $this->createMock(WPFunctions::class);
$wpMock->method('currentTime')->willReturn(strtotime($currentTime));
$wpMock->method('wpTimezone')->willReturn(new \DateTimeZone('America/New_York'));
$wpMock->method('currentDatetime')->willReturn(
new \DateTimeImmutable($currentTime, new \DateTimeZone('America/New_York'))
);
$scheduler = $this->getServiceWithOverrides(Scheduler::class, ['wp' => $wpMock]);
// Cron was set by user in NewYork timezone (0 10 * * *) in UTC it would be (0 14 * * *)
verify($scheduler->getPreviousRunDate('0 10 * * *'))