mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fixed: take into account the first iteration of the cronjob
This commit is contained in:
parent
a7842b2597
commit
b0fcffea2d
@ -27,6 +27,10 @@ final readonly class CollateAddressWithReferenceOrPostalCodeCronJob implements C
|
||||
|
||||
public function canRun(?CronJobExecution $cronJobExecution): bool
|
||||
{
|
||||
if (null === $cronJobExecution) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$now = $this->clock->now();
|
||||
|
||||
return $now->sub(new \DateInterval('PT6H')) > $cronJobExecution->getLastStart();
|
||||
|
@ -29,10 +29,12 @@ class CollateAddressWithReferenceOrPostalCodeCronJobTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideDataCanRun
|
||||
*/
|
||||
public function testCanRun(\DateTimeImmutable $now, \DateTimeImmutable $lastExecution, bool $expected): void
|
||||
public function testCanRun(\DateTimeImmutable $now, ?\DateTimeImmutable $lastExecution, bool $expected): void
|
||||
{
|
||||
$execution = new CronJobExecution('collate-address');
|
||||
$execution ->setLastStart($lastExecution);
|
||||
$execution = match ($lastExecution) {
|
||||
null => null,
|
||||
default => (new CronJobExecution('collate-address'))->setLastStart($lastExecution),
|
||||
};
|
||||
|
||||
$clock = new MockClock($now);
|
||||
$collator = $this->prophesize(CollateAddressWithReferenceOrPostalCodeInterface::class);
|
||||
@ -60,6 +62,7 @@ class CollateAddressWithReferenceOrPostalCodeCronJobTest extends TestCase
|
||||
yield [new \DateTimeImmutable('2023-07-10T12:00:00'), new \DateTimeImmutable('2023-07-10T11:00:00'), false];
|
||||
yield [new \DateTimeImmutable('2023-07-10T12:00:00'), new \DateTimeImmutable('2023-07-10T05:00:00'), true];
|
||||
yield [new \DateTimeImmutable('2023-07-10T12:00:00'), new \DateTimeImmutable('2023-07-01T12:00:00'), true];
|
||||
yield [new \DateTimeImmutable('2023-07-10T12:00:00'), null, true];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user