diff --git a/src/Bundle/ChillMainBundle/Export/ExportConfigNormalizer.php b/src/Bundle/ChillMainBundle/Export/ExportConfigNormalizer.php index 46bd8b202..c94e7ba03 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportConfigNormalizer.php +++ b/src/Bundle/ChillMainBundle/Export/ExportConfigNormalizer.php @@ -17,7 +17,6 @@ use Chill\MainBundle\Form\Type\Export\AggregatorType; use Chill\MainBundle\Form\Type\Export\ExportType; use Chill\MainBundle\Form\Type\Export\FilterType; use Chill\MainBundle\Repository\CenterRepositoryInterface; -use Chill\MainBundle\Repository\RegroupmentRepository; use Chill\MainBundle\Repository\RegroupmentRepositoryInterface; /** diff --git a/src/Bundle/ChillMainBundle/Repository/RegroupmentRepository.php b/src/Bundle/ChillMainBundle/Repository/RegroupmentRepository.php index 76295cded..b78e5ccc1 100644 --- a/src/Bundle/ChillMainBundle/Repository/RegroupmentRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/RegroupmentRepository.php @@ -16,7 +16,6 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NoResultException; -use Doctrine\Persistence\ObjectRepository; final readonly class RegroupmentRepository implements RegroupmentRepositoryInterface { diff --git a/src/Bundle/ChillMainBundle/Repository/RegroupmentRepositoryInterface.php b/src/Bundle/ChillMainBundle/Repository/RegroupmentRepositoryInterface.php index f3337df7a..501cee8c5 100644 --- a/src/Bundle/ChillMainBundle/Repository/RegroupmentRepositoryInterface.php +++ b/src/Bundle/ChillMainBundle/Repository/RegroupmentRepositoryInterface.php @@ -1,5 +1,14 @@ getFilter(); - $em = $this->getContainer()->get(EntityManagerInterface::class); $normalized = $filter->normalizeFormData($data); $actual = $filter->denormalizeFormData($normalized, $version); diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/ExportGenerationControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/ExportGenerationControllerTest.php index ae92bfbcf..eff86072e 100644 --- a/src/Bundle/ChillMainBundle/Tests/Controller/ExportGenerationControllerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Controller/ExportGenerationControllerTest.php @@ -18,7 +18,6 @@ use Chill\MainBundle\Export\ExportManager; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; -use Psr\Log\NullLogger; use Symfony\Component\Security\Core\Security; use Symfony\Component\Serializer\SerializerInterface; use Twig\Environment; diff --git a/src/Bundle/ChillMainBundle/Tests/Export/ExportConfigNormalizerTest.php b/src/Bundle/ChillMainBundle/Tests/Export/ExportConfigNormalizerTest.php index 609a22894..34137ff26 100644 --- a/src/Bundle/ChillMainBundle/Tests/Export/ExportConfigNormalizerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Export/ExportConfigNormalizerTest.php @@ -19,7 +19,6 @@ use Chill\MainBundle\Export\ExportManager; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Repository\CenterRepositoryInterface; -use Chill\MainBundle\Repository\RegroupmentRepository; use Chill\MainBundle\Repository\RegroupmentRepositoryInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; diff --git a/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php b/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php index 77006cd81..8abfdc733 100644 --- a/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Export/ExportManagerTest.php @@ -17,7 +17,6 @@ use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\ExportManager; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\Export\ExportType; use Chill\MainBundle\Repository\UserRepositoryInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Test\PrepareCenterTrait; @@ -30,12 +29,10 @@ use Prophecy\Prophet; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\User\UserInterface; -use Symfony\Contracts\Translation\TranslatorInterface; /** * Test the export manager. @@ -480,7 +477,7 @@ class DummyExport implements ExportInterface public function initiateQuery(array $requiredModifiers, array $acl, array $data, \Chill\MainBundle\Export\ExportGenerationContext $context): QueryBuilder { - throw new \RuntimeException("not implemented"); + throw new \RuntimeException('not implemented'); } public function requiredRole(): string diff --git a/src/Bundle/ChillMainBundle/Tests/Export/SortExportElementTest.php b/src/Bundle/ChillMainBundle/Tests/Export/SortExportElementTest.php index bcc51f480..4b1c8d8cf 100644 --- a/src/Bundle/ChillMainBundle/Tests/Export/SortExportElementTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Export/SortExportElementTest.php @@ -156,7 +156,7 @@ class SortExportElementTest extends KernelTestCase return []; } - public function getTitle(): string|\Symfony\Contracts\Translation\TranslatableInterface + public function getTitle(): string|TranslatableInterface { return $this->title; } @@ -180,7 +180,7 @@ class SortExportElementTest extends KernelTestCase return new class ($title) implements FilterInterface { public function __construct(private readonly string $title) {} - public function getTitle(): string|\Symfony\Contracts\Translation\TranslatableInterface + public function getTitle(): string|TranslatableInterface { return $this->title; } @@ -207,7 +207,7 @@ class SortExportElementTest extends KernelTestCase return []; } - public function describeAction($data, $format = 'string'): string|\Symfony\Contracts\Translation\TranslatableInterface|array + public function describeAction($data, $format = 'string'): string|TranslatableInterface|array { return ['a', []]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ReferrerFilter.php index 5d6f40d5c..78afe0aeb 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ReferrerFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ReferrerFilter.php @@ -76,12 +76,18 @@ final readonly class ReferrerFilter implements FilterInterface public function normalizeFormData(array $formData): array { - return ['accepted_agents' => $this->normalizeDoctrineEntity($formData['accepted_agents']), 'agent_at' => $formData['agent_at']->normalize()]; + return [ + 'accepted_agents' => $this->normalizeDoctrineEntity($formData['accepted_agents']), + 'agent_at' => array_key_exists('agent_at', $formData) ? $formData['agent_at']?->normalize() : (new RollingDate(RollingDate::T_TODAY))->normalize(), + ]; } public function denormalizeFormData(array $formData, int $fromVersion): array { - return ['accepted_agents' => $this->denormalizeDoctrineEntity($formData['accepted_agents'], $this->userRepository), 'agent_at' => RollingDate::fromNormalized($formData['agent_at'])]; + return [ + 'accepted_agents' => $this->denormalizeDoctrineEntity($formData['accepted_agents'], $this->userRepository), + 'agent_at' => array_key_exists('agent_at', $formData) ? RollingDate::fromNormalized($formData['agent_at']) : new RollingDate(RollingDate::T_TODAY), + ]; } public function getFormDefaultData(): array diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodTest.php index cec1359c4..769bd886f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListAccompanyingPeriodTest.php @@ -12,7 +12,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Export; use Chill\MainBundle\Entity\Center; -use Chill\MainBundle\Entity\User; use Chill\MainBundle\Repository\CenterRepositoryInterface; use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface; @@ -27,7 +26,6 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Doctrine\ORM\EntityManagerInterface; use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; -use Symfony\Component\Security\Core\Security; /** * @internal diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/HandlingThirdPartyFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/HandlingThirdPartyFilterTest.php index 46a1a95e1..9e071adb1 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/HandlingThirdPartyFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/HandlingThirdPartyFilterTest.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Test\Export\AbstractFilterTest; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\HandlingThirdPartyFilter; use Chill\ThirdPartyBundle\Entity\ThirdParty; +use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository; use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender; use Doctrine\ORM\EntityManagerInterface; @@ -27,16 +28,19 @@ class HandlingThirdPartyFilterTest extends AbstractFilterTest { private ThirdPartyRender $thirdPartyRender; + private ThirdPartyRepository $thirdPartyRepository; + protected function setUp(): void { parent::setUp(); self::bootKernel(); $this->thirdPartyRender = self::getContainer()->get(ThirdPartyRender::class); + $this->thirdPartyRepository = self::getContainer()->get(ThirdPartyRepository::class); } public function getFilter() { - return new HandlingThirdPartyFilter($this->thirdPartyRender); + return new HandlingThirdPartyFilter($this->thirdPartyRender, $this->thirdPartyRepository); } public static function getFormData(): array diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ReferrerFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ReferrerFilterTest.php index d185ac499..0a1583cf5 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ReferrerFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/ReferrerFilterTest.php @@ -59,6 +59,49 @@ final class ReferrerFilterTest extends AbstractFilterTest return $data; } + /** + * @dataProvider dataProviderFormDataToNormalize + */ + public function testDataNormalization(array $data, int $version, array $expected): void + { + $filter = $this->getFilter(); + + $normalized = $filter->normalizeFormData($data); + $actual = $filter->denormalizeFormData($normalized, $version); + + self::assertEqualsCanonicalizing(array_keys($expected), array_keys($actual)); + } + + public static function dataProviderFormDataToNormalize(): iterable + { + self::bootKernel(); + $em = self::getContainer()->get(EntityManagerInterface::class); + $users = array_slice($em->getRepository(User::class)->findAll(), 0, 1); + + yield [ + [ + 'accepted_agents' => [$users[0]], + 'agent_at' => new RollingDate(RollingDate::T_TODAY), + ], + 1, + [ + 'accepted_agents' => [$users[0]], + 'agent_at' => new RollingDate(RollingDate::T_TODAY), + ], + ]; + + yield [ + [ + 'accepted_agents' => [$users[0]], + ], + 1, + [ + 'accepted_agents' => [$users[0]], + 'agent_at' => new RollingDate(RollingDate::T_TODAY), + ], + ]; + } + public static function getQueryBuilders(): iterable { self::bootKernel();