mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-07 23:34:58 +00:00
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.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?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];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user