Bootstrap encoder for documents

This commit is contained in:
2021-11-22 09:05:15 +00:00
parent 46a4afe1b3
commit d0bf47e0d5
25 changed files with 992 additions and 91 deletions

View File

@@ -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' => ''
];
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Serializer\Normalizer;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Serializer\Normalizer\PersonJsonNormalizer;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class PersonJsonNormalizerTest extends KernelTestCase
{
private NormalizerInterface $normalizer;
protected function setUp()
{
self::bootKernel();
$this->normalizer = self::$container->get(NormalizerInterface::class);
}
public function testNormalization()
{
$person = new Person();
$result = $this->normalizer->normalize($person, 'json', [AbstractNormalizer::GROUPS => [ 'read' ]]);
$this->assertIsArray($result);
}
}