mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add groups on household serialization
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Serializer\Normalizer;
|
||||
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
|
||||
class HouseholdNormalizerTest extends KernelTestCase
|
||||
{
|
||||
private ?NormalizerInterface $normalizer;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->normalizer= self::$container->get(NormalizerInterface::class);
|
||||
}
|
||||
|
||||
public function testNormalizationRecursive()
|
||||
{
|
||||
$person = new 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'));
|
||||
|
||||
$household->addMember($member);
|
||||
|
||||
$normalized = $this->normalizer->normalize($household,
|
||||
'json', [ 'groups' => [ 'read' ]]);
|
||||
|
||||
$this->assertIsArray($normalized);
|
||||
$this->assertArrayHasKey('type', $normalized);
|
||||
$this->assertEquals('household', $normalized['type']);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user