Partage d'export enregistré et génération asynchrone des exports

This commit is contained in:
2025-07-08 13:53:25 +00:00
parent c4cc0baa8e
commit 8bc16dadb0
447 changed files with 14134 additions and 3854 deletions

View File

@@ -0,0 +1,78 @@
<?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\Regroupement;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Regroupment;
use Chill\MainBundle\Service\Regroupement\CenterRegroupementResolver;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
class CenterRegroupementResolverTest extends TestCase
{
private static CenterRegroupementResolver $resolver;
public static function setUpBeforeClass(): void
{
self::$resolver = new CenterRegroupementResolver();
}
/**
* @dataProvider provideData
*/
public function testResolveCenter(array $groups, array $centers, array $expected): void
{
$actual = self::$resolver->resolveCenters($groups, $centers);
self::assertEquals(count($expected), count($actual));
foreach ($expected as $center) {
self::assertContains($center, $actual);
}
}
public static function provideData(): iterable
{
$centerA = new Center();
$centerB = new Center();
$centerC = new Center();
$centerD = new Center();
$groupA = new Regroupment();
$groupA->addCenter($centerA)->addCenter($centerB);
$groupB = new Regroupment();
$groupB->addCenter($centerA)->addCenter($centerB)->addCenter($centerC);
yield [
[$groupA],
[],
[$centerA, $centerB],
];
yield [
[$groupA, $groupB],
[],
[$centerA, $centerB, $centerC],
];
yield [
[$groupA, $groupB],
[$centerB, $centerD],
[$centerA, $centerB, $centerC, $centerD],
];
}
}

View File

@@ -0,0 +1,96 @@
<?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\Regroupement;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Regroupment;
use Chill\MainBundle\Service\Regroupement\RegroupementFiltering;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
class RegroupementFilteringTest extends TestCase
{
private static RegroupementFiltering $regroupementFiltering;
public static function setUpBeforeClass(): void
{
self::$regroupementFiltering = new RegroupementFiltering();
}
/**
* @dataProvider provideDataForFilterContainsAtLeastOnCenter
*/
public function testFilterContainsAtLeastOnCenter(array $groups, array $centers, array $expected): void
{
$actual = self::$regroupementFiltering->filterContainsAtLeastOneCenter($groups, $centers);
self::assertEquals(count($expected), count($actual));
self::assertTrue(array_is_list($actual));
foreach ($expected as $center) {
self::assertContains($center, $actual);
}
}
public static function provideDataForFilterContainsAtLeastOnCenter(): iterable
{
$centerA = new Center();
$centerB = new Center();
$centerC = new Center();
$centerD = new Center();
$groupA = new Regroupment();
$groupA->addCenter($centerA)->addCenter($centerB);
$groupB = new Regroupment();
$groupB->addCenter($centerA)->addCenter($centerB)->addCenter($centerC);
$groupC = new Regroupment();
$groupC->addCenter($centerA)->addCenter($centerD);
yield [
[$groupA, $groupB],
[],
[],
];
yield [
[$groupA, $groupB],
[$centerA, $centerB, $centerC],
[$groupA, $groupB],
];
yield [
[$groupA, $groupC],
[$centerD],
[$groupC],
];
yield [
[$groupA],
[$centerB, $centerD],
[$groupA],
];
yield [
[$groupA],
[new Center()],
[],
];
}
}

View File

@@ -14,6 +14,7 @@ namespace Services\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Clock\MockClock;
/**
* @internal
@@ -22,11 +23,9 @@ use PHPUnit\Framework\TestCase;
*/
final class RollingDateConverterTest extends TestCase
{
private RollingDateConverter $converter;
protected function setUp(): void
private function buildConverter(\DateTimeImmutable|string $pivot = 'now'): RollingDateConverter
{
$this->converter = new RollingDateConverter();
return new RollingDateConverter(new MockClock($pivot));
}
public function testConversionFixedDate()
@@ -35,7 +34,7 @@ final class RollingDateConverterTest extends TestCase
$this->assertEquals(
'2022-01-01',
$this->converter->convert($rollingDate)->format('Y-m-d')
$this->buildConverter()->convert($rollingDate)->format('Y-m-d')
);
}
@@ -43,7 +42,7 @@ final class RollingDateConverterTest extends TestCase
{
$rollingDate = new RollingDate(RollingDate::T_YEAR_PREVIOUS_START);
$actual = $this->converter->convert($rollingDate);
$actual = $this->buildConverter()->convert($rollingDate);
$this->assertEquals(
(int) (new \DateTimeImmutable('now'))->format('Y') - 1,
@@ -63,7 +62,21 @@ final class RollingDateConverterTest extends TestCase
$this->assertEquals(
\DateTime::createFromFormat($format, $expectedDateTime),
$this->converter->convert($rollingDate)
$this->buildConverter()->convert($rollingDate)
);
}
/**
* @dataProvider generateDataConversionDate
*/
public function testConvertOnClock(string $roll, string $expectedDateTime, string $format)
{
$pivot = \DateTimeImmutable::createFromFormat('Y-m-d His', '2022-11-07 000000');
$rollingDate = new RollingDate($roll, null);
$this->assertEquals(
\DateTime::createFromFormat($format, $expectedDateTime),
$this->buildConverter($pivot)->convert($rollingDate)
);
}

View File

@@ -0,0 +1,45 @@
<?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\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
class RollingDateTest extends TestCase
{
public function testNormalizationDenormalizationProcessWithoutPivotDate(): void
{
$date = new RollingDate(RollingDate::T_YEAR_PREVIOUS_START);
$actual = RollingDate::fromNormalized($date->normalize());
self::assertEquals(RollingDate::T_YEAR_PREVIOUS_START, $actual->getRoll());
self::assertNull($actual->getFixedDate());
self::assertEquals($date->getPivotDate()?->getTimestamp(), $actual->getPivotDate()?->getTimestamp());
}
public function testNormalizationDenormalizationProcessWithPivotDate(): void
{
$date = new RollingDate(RollingDate::T_FIXED_DATE, $fixed = new \DateTimeImmutable('now'));
$actual = RollingDate::fromNormalized($date->normalize());
self::assertEquals(RollingDate::T_FIXED_DATE, $actual->getRoll());
self::assertEquals($fixed, $actual->getFixedDate());
self::assertEquals($date->getPivotDate()?->getTimestamp(), $actual->getPivotDate()?->getTimestamp());
}
}

View File

@@ -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];
}
}