mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\Tests\Services\AddressGeographicalUnit;
|
|
|
|
use Chill\MainBundle\Entity\CronJobExecution;
|
|
use DateTimeImmutable;
|
|
use Doctrine\DBAL\Connection;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
/**
|
|
* @internal
|
|
* @coversNothing
|
|
*/
|
|
final class RefreshAddressToGeographicalUnitMaterializedViewCronJobTest extends KernelTestCase
|
|
{
|
|
private Connection $connection;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::bootKernel();
|
|
$this->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();
|
|
}
|
|
}
|