mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-24 00:23:50 +00:00
[Addresses] add a cronjob to collate addresses with reference
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?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 Services\AddressGeographicalUnit;
|
||||
|
||||
use Chill\MainBundle\Entity\CronJobExecution;
|
||||
use Chill\MainBundle\Service\AddressGeographicalUnit\CollateAddressWithReferenceOrPostalCodeCronJob;
|
||||
use Chill\MainBundle\Service\AddressGeographicalUnit\CollateAddressWithReferenceOrPostalCodeInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Component\Clock\MockClock;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CollateAddressWithReferenceOrPostalCodeCronJobTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @dataProvider provideDataCanRun
|
||||
*/
|
||||
public function testCanRun(\DateTimeImmutable $now, \DateTimeImmutable $lastExecution, bool $expected): void
|
||||
{
|
||||
$execution = new CronJobExecution('collate-address');
|
||||
$execution ->setLastStart($lastExecution);
|
||||
|
||||
$clock = new MockClock($now);
|
||||
$collator = $this->prophesize(CollateAddressWithReferenceOrPostalCodeInterface::class);
|
||||
|
||||
$job = new CollateAddressWithReferenceOrPostalCodeCronJob($clock, $collator->reveal());
|
||||
|
||||
self::assertEquals($expected, $job->canRun($execution));
|
||||
}
|
||||
|
||||
public function testRun(): void
|
||||
{
|
||||
$clock = new MockClock();
|
||||
$collator = $this->prophesize(CollateAddressWithReferenceOrPostalCodeInterface::class);
|
||||
$collator->__invoke(0)->shouldBeCalledOnce();
|
||||
$collator->__invoke(0)->willReturn(1);
|
||||
|
||||
$job = new CollateAddressWithReferenceOrPostalCodeCronJob($clock, $collator->reveal());
|
||||
|
||||
$actual = $job->run(['last-max-id' => 0]);
|
||||
self::assertEquals(['last-max-id' => 1], $actual);
|
||||
}
|
||||
|
||||
public static function provideDataCanRun(): iterable
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user