mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\PersonBundle\Tests\Serializer\Normalizer;
|
|
|
|
use Chill\PersonBundle\Entity\Household\Household;
|
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
|
use Chill\PersonBundle\Entity\Household\Position;
|
|
use Chill\PersonBundle\Entity\Person;
|
|
use DateTimeImmutable;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
|
|
/**
|
|
* @internal
|
|
* @coversNothing
|
|
*/
|
|
final class HouseholdNormalizerTest extends KernelTestCase
|
|
{
|
|
private EntityManagerInterface $entityManager;
|
|
|
|
private ?NormalizerInterface $normalizer;
|
|
|
|
private array $toDelete;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
self::bootKernel();
|
|
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
|
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
|
}
|
|
|
|
public function testNormalizationRecursive()
|
|
{
|
|
$person = new Person();
|
|
$person->setFirstName('ok')->setLastName('ok');
|
|
$this->entityManager->persist($person);
|
|
$member = new HouseholdMember();
|
|
$household = new Household();
|
|
$position = (new Position())
|
|
->setShareHousehold(true)
|
|
->setAllowHolder(true);
|
|
|
|
$member->setPerson($person)
|
|
->setStartDate(new DateTimeImmutable('1 year ago'))
|
|
->setEndDate(new DateTimeImmutable('1 month ago'))
|
|
->setPosition($position);
|
|
|
|
$household->addMember($member);
|
|
|
|
$normalized = $this->normalizer->normalize(
|
|
$household,
|
|
'json',
|
|
['groups' => ['read']]
|
|
);
|
|
|
|
$this->assertIsArray($normalized);
|
|
$this->assertArrayHasKey('type', $normalized);
|
|
$this->assertEquals('household', $normalized['type']);
|
|
}
|
|
}
|