connection = self::$container->get(Connection::class); } public function testCanRun(): void { // As the can run is executed one of ten, this should be executed at least one after // 10 + 5 executions $job = new \Chill\MainBundle\Service\AddressGeographicalUnit\RefreshAddressToGeographicalUnitMaterializedViewCronJob( $this->connection ); $lastExecution = new CronJobExecution($job->getKey()); $lastExecution->setLastStart(new DateTimeImmutable('2 days ago')); $executedForFirstTime = 0; $executedAfterPreviousExecution = 0; for ($round = 0; 20 > $round; ++$round ) { if ($job->canRun(null)) { ++$executedForFirstTime; } if ($job->canRun($lastExecution)) { ++$executedAfterPreviousExecution; } } $this->assertGreaterThan(0, $executedForFirstTime); $this->assertGreaterThan(0, $executedAfterPreviousExecution); } public function testFullRun(): void { $job = new \Chill\MainBundle\Service\AddressGeographicalUnit\RefreshAddressToGeographicalUnitMaterializedViewCronJob( $this->connection ); $lastExecution = new CronJobExecution($job->getKey()); $lastExecution->setLastStart(new DateTimeImmutable('2 days ago')); $this->assertIsBool($job->canRun($lastExecution)); $job->run(); } }