diff --git a/src/Bundle/ChillMainBundle/Entity/Gender.php b/src/Bundle/ChillMainBundle/Entity/Gender.php index d1baad400..59c0bd134 100644 --- a/src/Bundle/ChillMainBundle/Entity/Gender.php +++ b/src/Bundle/ChillMainBundle/Entity/Gender.php @@ -21,13 +21,13 @@ use Symfony\Component\Validator\Constraints as Assert; #[ORM\Table(name: 'chill_main_gender')] class Gender { - #[Serializer\Groups(['read', 'docgen:read'])] + #[Serializer\Groups(['read'])] #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)] private ?int $id = null; - #[Serializer\Groups(['read', 'docgen:read'])] + #[Serializer\Groups(['read'])] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)] private array $label = []; @@ -36,7 +36,7 @@ class Gender private bool $active = true; #[Assert\NotNull(message: 'You must choose a gender translation')] - #[Serializer\Groups(['read', 'docgen:read'])] + #[Serializer\Groups(['read'])] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, enumType: GenderEnum::class)] private GenderEnum $genderTranslation; diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/GenderDocGenNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/GenderDocGenNormalizer.php similarity index 95% rename from src/Bundle/ChillPersonBundle/Serializer/Normalizer/GenderDocGenNormalizer.php rename to src/Bundle/ChillMainBundle/Serializer/Normalizer/GenderDocGenNormalizer.php index 3e9366673..f7dd84dfc 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/GenderDocGenNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/GenderDocGenNormalizer.php @@ -9,7 +9,7 @@ declare(strict_types=1); * the LICENSE file that was distributed with this source code. */ -namespace Chill\PersonBundle\Serializer\Normalizer; +namespace Chill\MainBundle\Serializer\Normalizer; use Chill\MainBundle\Entity\Gender; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; diff --git a/src/Bundle/ChillMainBundle/Tests/Serializer/Normalizer/GenderDocGenNormalizerTest.php b/src/Bundle/ChillMainBundle/Tests/Serializer/Normalizer/GenderDocGenNormalizerTest.php new file mode 100644 index 000000000..df72fd39c --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Serializer/Normalizer/GenderDocGenNormalizerTest.php @@ -0,0 +1,69 @@ +translatableStringHelper = $this->createMock(TranslatableStringHelperInterface::class); + $this->normalizer = new GenderDocGenNormalizer($this->translatableStringHelper); + } + + public function testSupportsNormalizationReturnsTrueForGenderInstance(): void + { + $gender = $this->createMock(Gender::class); + $this->assertTrue($this->normalizer->supportsNormalization($gender)); + } + + public function testSupportsNormalizationReturnsFalseForNonGenderInstance(): void + { + $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass())); + } + + public function testNormalizeReturnsCorrectData(): void + { + $gender = $this->createMock(Gender::class); + + $gender->method('getId')->willReturn(1); + $gender->method('getLabel')->willReturn(['fr' => 'homme', 'en' => 'man']); + $gender->method('getGenderTranslation')->willReturn(GenderEnum::MALE); + + $this->translatableStringHelper + ->method('localize') + ->with(['fr' => 'homme', 'en' => 'man']) + ->willReturn('homme'); + + $expected = [ + 'id' => 1, + 'label' => 'homme', + 'genderTranslation' => GenderEnum::MALE, + ]; + + $this->assertEquals($expected, $this->normalizer->normalize($gender)); + } +} +