mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
Bootstrap encoder for documents
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Serializer\Normalizer;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonAltName;
|
||||
use Chill\PersonBundle\Serializer\Normalizer\PersonDocGenNormalizer;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
class PersonDocGenNormalizerTest extends KernelTestCase
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateData
|
||||
*/
|
||||
public function testNormalize(?Person $person, $expected, $msg)
|
||||
{
|
||||
$normalized = $this->normalizer->normalize($person, 'docgen', ['docgen:expects' => Person::class]);
|
||||
|
||||
$this->assertEquals($expected, $normalized, $msg);
|
||||
}
|
||||
|
||||
public function generateData()
|
||||
{
|
||||
$person = new Person();
|
||||
$person
|
||||
->setFirstName('Renaud')
|
||||
->setLastName('Mégane')
|
||||
;
|
||||
|
||||
$expected = \array_merge(
|
||||
self::BLANK, ['firstname' => 'Renaud', 'lastname' => 'Mégane',
|
||||
'text' => 'Renaud Mégane']
|
||||
);
|
||||
|
||||
yield [$person, $expected, 'partial normalization for a person'];
|
||||
|
||||
yield [null, self::BLANK, 'normalization for a null person'];
|
||||
}
|
||||
|
||||
|
||||
private const BLANK = [
|
||||
'firstname' => '',
|
||||
'lastname' => '',
|
||||
'altNames' => '',
|
||||
'text' => '',
|
||||
'birthdate' => ['short' => '', 'long' => ''],
|
||||
'deathdate' => ['short' => '', 'long' => ''],
|
||||
'gender' => '',
|
||||
'maritalStatus' => '',
|
||||
'maritalStatusDate' => ['short' => '', 'long' => ''],
|
||||
'email' => '',
|
||||
'firstPhoneNumber' => '',
|
||||
'fixPhoneNumber' => '',
|
||||
'mobilePhoneNumber' => '',
|
||||
'nationality' => '',
|
||||
'placeOfBirth' => '',
|
||||
'memo' => '',
|
||||
'numberOfChildren' => ''
|
||||
];
|
||||
|
||||
}
|
Reference in New Issue
Block a user