Add RegroupmentRepository dependency to ExportConfigNormalizer

This change introduces the RegroupmentRepositoryInterface as a new dependency in the ExportConfigNormalizer. It updates related test cases to mock and pass the new repository, ensuring proper coverage and functionality.
This commit is contained in:
Julien Fastré 2025-04-08 15:24:40 +02:00
parent 2b88593e64
commit 1c04219859
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -19,6 +19,8 @@ use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Repository\CenterRepositoryInterface; use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Repository\RegroupmentRepository;
use Chill\MainBundle\Repository\RegroupmentRepositoryInterface;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
@ -62,6 +64,8 @@ class ExportConfigNormalizerTest extends TestCase
$exportManager->getAggregator('aggregatorDisabled')->willReturn($aggregatorDisabled->reveal()); $exportManager->getAggregator('aggregatorDisabled')->willReturn($aggregatorDisabled->reveal());
$exportManager->getExport('export')->willReturn($export->reveal()); $exportManager->getExport('export')->willReturn($export->reveal());
$regroupmentRepository = $this->prophesize(RegroupmentRepositoryInterface::class);
$center = $this->prophesize(Center::class); $center = $this->prophesize(Center::class);
$center->getId()->willReturn(10); $center->getId()->willReturn(10);
@ -98,7 +102,11 @@ class ExportConfigNormalizerTest extends TestCase
], ],
]; ];
$exportConfigNormalizer = new ExportConfigNormalizer($exportManager->reveal(), $this->prophesize(CenterRepositoryInterface::class)->reveal()); $exportConfigNormalizer = new ExportConfigNormalizer(
$exportManager->reveal(),
$this->prophesize(CenterRepositoryInterface::class)->reveal(),
$regroupmentRepository->reveal()
);
$actual = $exportConfigNormalizer->normalizeConfig('export', $formData); $actual = $exportConfigNormalizer->normalizeConfig('export', $formData);
@ -136,6 +144,8 @@ class ExportConfigNormalizerTest extends TestCase
$centerRepository = $this->prophesize(CenterRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class);
$centerRepository->find(10)->willReturn($center = new Center()); $centerRepository->find(10)->willReturn($center = new Center());
$regroupmentRepository = $this->prophesize(RegroupmentRepositoryInterface::class);
$serialized = [ $serialized = [
'centers' => ['regroupments' => [], 'centers' => [10]], 'centers' => ['regroupments' => [], 'centers' => [10]],
'export' => ['form' => ['test' => '0'], 'version' => 1], 'export' => ['form' => ['test' => '0'], 'version' => 1],
@ -169,7 +179,7 @@ class ExportConfigNormalizerTest extends TestCase
'centers' => ['centers' => [$center], 'regroupments' => []], 'centers' => ['centers' => [$center], 'regroupments' => []],
]; ];
$exportConfigNormalizer = new ExportConfigNormalizer($exportManager->reveal(), $centerRepository->reveal()); $exportConfigNormalizer = new ExportConfigNormalizer($exportManager->reveal(), $centerRepository->reveal(), $regroupmentRepository->reveal());
$actual = $exportConfigNormalizer->denormalizeConfig('export', $serialized, true); $actual = $exportConfigNormalizer->denormalizeConfig('export', $serialized, true);
self::assertEquals($expected, $actual); self::assertEquals($expected, $actual);
@ -208,6 +218,8 @@ class ExportConfigNormalizerTest extends TestCase
$center = $this->prophesize(Center::class); $center = $this->prophesize(Center::class);
$center->getId()->willReturn(10); $center->getId()->willReturn(10);
$regroupmentRepository = $this->prophesize(RegroupmentRepositoryInterface::class);
$formData = [ $formData = [
'centers' => ['centers' => [$center->reveal()]], 'centers' => ['centers' => [$center->reveal()]],
'export' => [], 'export' => [],
@ -241,7 +253,7 @@ class ExportConfigNormalizerTest extends TestCase
], ],
]; ];
$exportConfigNormalizer = new ExportConfigNormalizer($exportManager->reveal(), $this->prophesize(CenterRepositoryInterface::class)->reveal()); $exportConfigNormalizer = new ExportConfigNormalizer($exportManager->reveal(), $this->prophesize(CenterRepositoryInterface::class)->reveal(), $regroupmentRepository->reveal());
$actual = $exportConfigNormalizer->normalizeConfig('export', $formData); $actual = $exportConfigNormalizer->normalizeConfig('export', $formData);
@ -279,6 +291,8 @@ class ExportConfigNormalizerTest extends TestCase
$centerRepository = $this->prophesize(CenterRepositoryInterface::class); $centerRepository = $this->prophesize(CenterRepositoryInterface::class);
$centerRepository->find(10)->willReturn($center = new Center()); $centerRepository->find(10)->willReturn($center = new Center());
$regroupmentRepository = $this->prophesize(RegroupmentRepositoryInterface::class);
$serialized = [ $serialized = [
'centers' => ['centers' => [10], 'regroupments' => []], 'centers' => ['centers' => [10], 'regroupments' => []],
'export' => ['form' => [], 'version' => 1], 'export' => ['form' => [], 'version' => 1],
@ -312,7 +326,7 @@ class ExportConfigNormalizerTest extends TestCase
'centers' => ['centers' => [$center], 'regroupments' => []], 'centers' => ['centers' => [$center], 'regroupments' => []],
]; ];
$exportConfigNormalizer = new ExportConfigNormalizer($exportManager->reveal(), $centerRepository->reveal()); $exportConfigNormalizer = new ExportConfigNormalizer($exportManager->reveal(), $centerRepository->reveal(), $regroupmentRepository->reveal());
$actual = $exportConfigNormalizer->denormalizeConfig('export', $serialized, true); $actual = $exportConfigNormalizer->denormalizeConfig('export', $serialized, true);
self::assertEquals($expected, $actual); self::assertEquals($expected, $actual);