mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add unit test for GenderDocGenNormalizer and move file to MainBundle
This commit is contained in:
parent
f4f5153ed0
commit
5afb92d549
@ -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;
|
||||
|
||||
|
@ -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;
|
@ -0,0 +1,69 @@
|
||||
<?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 Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Entity\Gender;
|
||||
use Chill\MainBundle\Entity\GenderEnum;
|
||||
use Chill\MainBundle\Serializer\Normalizer\GenderDocGenNormalizer;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class GenderDocGenNormalizerTest extends TestCase
|
||||
{
|
||||
private GenderDocGenNormalizer $normalizer;
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user