diff --git a/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJob.php b/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJob.php index b35a687dd..d2c9fc960 100644 --- a/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJob.php +++ b/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJob.php @@ -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(); diff --git a/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJobTest.php b/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJobTest.php index f8b4a547e..69eeca2da 100644 --- a/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJobTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCodeCronJobTest.php @@ -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]; } }