chill-bundles/src/Bundle/ChillMainBundle/Tests/Services/UserGroup/UserGroupRelatedToUserJobSyncCronJobTest.php
Julien Fastré fb1c34f9c1
Add UserGroup and UserJob synchronization feature
Implement UserGroupRelatedToUserJobSync to manage associations between UserGroups and UserJobs, including creating, updating, and removing relationships. Introduce a cron job to automate the synchronization process and add tests to ensure functionality. Update translations and repository logic as part of the implementation.
2025-04-25 13:07:52 +02:00

59 lines
1.8 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\UserGroup;
use Chill\MainBundle\Entity\CronJobExecution;
use Chill\MainBundle\Service\UserGroup\UserGroupRelatedToUserJobSyncCronJob;
use Chill\MainBundle\Service\UserGroup\UserGroupRelatedToUserJobSyncInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Clock\MockClock;
/**
* @internal
*
* @coversNothing
*/
class UserGroupRelatedToUserJobSyncCronJobTest extends TestCase
{
use ProphecyTrait;
/**
* @dataProvider canRunDataProvider
*/
public function testCanRun(\DateTimeImmutable $now, ?\DateTimeImmutable $lastStartExecution, bool $exected): void
{
$clock = new MockClock($now);
$job = $this->prophesize(UserGroupRelatedToUserJobSyncInterface::class);
$cronJob = new UserGroupRelatedToUserJobSyncCronJob($clock, $job->reveal());
if (null !== $lastStartExecution) {
$lastExecution = new CronJobExecution('user-group-related-to-user-job-sync');
$lastExecution->setLastStart($lastStartExecution);
}
$actual = $cronJob->canRun($lastExecution ?? null);
self::assertEquals($exected, $actual);
}
public static function canRunDataProvider(): iterable
{
$now = new \DateTimeImmutable('2025-04-27T00:00:00Z');
yield 'never executed' => [$now, null, true];
yield 'executed 12 hours ago' => [$now, new \DateTimeImmutable('2025-04-26T12:00:00Z'), false];
yield 'executed more than 12 hours ago' => [$now, new \DateTimeImmutable('2025-04-25T12:00:00Z'), true];
}
}