mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
docgen normalization budget: fix budget when person is null
This commit is contained in:
@@ -276,8 +276,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
/**
|
||||
* The person's first name.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @Assert\NotBlank(message="The firstname cannot be empty")
|
||||
* @Assert\Length(
|
||||
@@ -290,8 +288,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
* fullname canonical. Read-only field, which is calculated by
|
||||
* the database.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="text", nullable=true)
|
||||
*/
|
||||
private string $fullnameCanonical = '';
|
||||
@@ -345,8 +341,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
/**
|
||||
* The person's last name.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
* @Assert\NotBlank(message="The lastname cannot be empty")
|
||||
* @Assert\Length(
|
||||
|
@@ -11,7 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\BudgetBundle\Service\Summary\SummaryBudget;
|
||||
use Chill\BudgetBundle\Service\Summary\SummaryBudgetInterface;
|
||||
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\Civility;
|
||||
@@ -45,7 +45,7 @@ class PersonDocGenNormalizer implements
|
||||
|
||||
private RelationshipRepository $relationshipRepository;
|
||||
|
||||
private SummaryBudget $summaryBudget;
|
||||
private SummaryBudgetInterface $summaryBudget;
|
||||
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
@@ -56,7 +56,7 @@ class PersonDocGenNormalizer implements
|
||||
RelationshipRepository $relationshipRepository,
|
||||
TranslatorInterface $translator,
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
SummaryBudget $summaryBudget
|
||||
SummaryBudgetInterface $summaryBudget
|
||||
) {
|
||||
$this->personRender = $personRender;
|
||||
$this->relationshipRepository = $relationshipRepository;
|
||||
@@ -214,6 +214,14 @@ class PersonDocGenNormalizer implements
|
||||
$data['relations'] = [];
|
||||
}
|
||||
|
||||
if ($context['docgen:person:with-budget'] ?? false) {
|
||||
$data['budget']['person'] = $this->summaryBudget->getSummaryForPerson(null);
|
||||
|
||||
if ($context['docgen:person:with-household'] ?? false) {
|
||||
$data['budget']['household'] = $this->summaryBudget->getSummaryForHousehold(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Serializer\Normalizer;
|
||||
|
||||
use Chill\BudgetBundle\Service\Summary\SummaryBudgetInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
@@ -72,6 +73,17 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||
}
|
||||
|
||||
public function dataGeneratorNormalizationNullOrNotNullHaveSameKeys(): iterable
|
||||
{
|
||||
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read']]];
|
||||
|
||||
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-household' => true]];
|
||||
|
||||
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-relations' => true]];
|
||||
|
||||
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-budget' => true]];
|
||||
}
|
||||
|
||||
public function generateData()
|
||||
{
|
||||
$person = new Person();
|
||||
@@ -90,12 +102,16 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
||||
yield [null, self::BLANK, 'normalization for a null person'];
|
||||
}
|
||||
|
||||
public function testNormalizationNullOrNotNullHaveSameKeys()
|
||||
/**
|
||||
* @dataProvider dataGeneratorNormalizationNullOrNotNullHaveSameKeys
|
||||
*
|
||||
* @param mixed $context
|
||||
*/
|
||||
public function testNormalizationNullOrNotNullHaveSameKeys($context)
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
$period = new Person();
|
||||
$notNullData = $this->buildPersonNormalizer()->normalize($period, 'docgen', ['docgen:expects' => Person::class]);
|
||||
$nullData = $this->buildPersonNormalizer()->normalize(null, 'docgen', ['docgen:expects' => Person::class]);
|
||||
$notNullData = $this->buildPersonNormalizer()->normalize($period, 'docgen', $context);
|
||||
$nullData = $this->buildPersonNormalizer()->normalize(null, 'docgen', $context);
|
||||
|
||||
$this->assertEqualsCanonicalizing(
|
||||
array_keys($notNullData),
|
||||
@@ -131,7 +147,6 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
||||
|
||||
public function testNormalizePersonWithHousehold()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
$household = new Household();
|
||||
$person = new Person();
|
||||
$person
|
||||
@@ -172,7 +187,6 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
||||
|
||||
public function testNormalizePersonWithRelationships()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
$person = (new Person())->setFirstName('Renaud')->setLastName('megane');
|
||||
$father = (new Person())->setFirstName('Clément')->setLastName('megane');
|
||||
$mother = (new Person())->setFirstName('Mireille')->setLastName('Mathieu');
|
||||
@@ -235,13 +249,25 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
||||
?RelationshipRepository $relationshipRepository = null,
|
||||
?TranslatorInterface $translator = null,
|
||||
?TranslatableStringHelper $translatableStringHelper = null,
|
||||
?NormalizerInterface $normalizer = null
|
||||
?NormalizerInterface $normalizer = null,
|
||||
?SummaryBudgetInterface $summaryBudget = null
|
||||
): PersonDocGenNormalizer {
|
||||
if (null === $summaryBudget) {
|
||||
$summaryBudget = $this->prophesize(SummaryBudgetInterface::class);
|
||||
$summaryBudget->getSummaryForHousehold(Argument::any())->willReturn(
|
||||
['resources' => [], 'charges' => []]
|
||||
);
|
||||
$summaryBudget->getSummaryForPerson(Argument::any())->willReturn(
|
||||
['resources' => [], 'charges' => []]
|
||||
);
|
||||
}
|
||||
|
||||
$personDocGenNormalizer = new PersonDocGenNormalizer(
|
||||
$personRender ?? self::$container->get(PersonRender::class),
|
||||
$relationshipRepository ?? self::$container->get(RelationshipRepository::class),
|
||||
$translator ?? self::$container->get(TranslatorInterface::class),
|
||||
$translatableStringHelper ?? self::$container->get(TranslatableStringHelperInterface::class)
|
||||
$translatableStringHelper ?? self::$container->get(TranslatableStringHelperInterface::class),
|
||||
$summaryBudget->reveal(),
|
||||
);
|
||||
|
||||
if (null === $normalizer) {
|
||||
@@ -259,13 +285,31 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
||||
?PersonRender $personRender = null,
|
||||
?RelationshipRepository $relationshipRepository = null,
|
||||
?TranslatorInterface $translator = null,
|
||||
?TranslatableStringHelper $translatableStringHelper = null
|
||||
?TranslatableStringHelper $translatableStringHelper = null,
|
||||
?SummaryBudgetInterface $summaryBudget = null
|
||||
): PersonDocGenNormalizer {
|
||||
if (null === $relationshipRepository) {
|
||||
$relationshipRepository = $this->prophesize(RelationshipRepository::class);
|
||||
$relationshipRepository->findByPerson(Argument::type(Person::class))->willReturn([]);
|
||||
$relationshipRepository = $relationshipRepository->reveal();
|
||||
}
|
||||
|
||||
if (null === $summaryBudget) {
|
||||
$summaryBudget = $this->prophesize(SummaryBudgetInterface::class);
|
||||
$summaryBudget->getSummaryForHousehold(Argument::any())->willReturn(
|
||||
['resources' => [], 'charges' => []]
|
||||
);
|
||||
$summaryBudget->getSummaryForPerson(Argument::any())->willReturn(
|
||||
['resources' => [], 'charges' => []]
|
||||
);
|
||||
}
|
||||
|
||||
$normalizer = new PersonDocGenNormalizer(
|
||||
$personRender ?? self::$container->get(PersonRender::class),
|
||||
$relationshipRepository ?? self::$container->get(RelationshipRepository::class),
|
||||
$relationshipRepository,
|
||||
$translator ?? self::$container->get(TranslatorInterface::class),
|
||||
$translatableStringHelper ?? self::$container->get(TranslatableStringHelperInterface::class)
|
||||
$translatableStringHelper ?? self::$container->get(TranslatableStringHelperInterface::class),
|
||||
$summaryBudget->reveal()
|
||||
);
|
||||
$normalizerManager = $this->prophesize(NormalizerInterface::class);
|
||||
$normalizerManager->supportsNormalization(Argument::any(), 'docgen', Argument::any())->willReturn(true);
|
||||
|
Reference in New Issue
Block a user