Refactor normalizers: update getSupportedTypes to include '*' => false, improve return type handling, and add dedicated test classes for SocialAction, SocialIssue, and other entities.

This commit is contained in:
2026-01-09 16:31:34 +01:00
parent 8ceb937e0e
commit 21cd0f7c45
14 changed files with 233 additions and 35 deletions

View File

@@ -363,6 +363,8 @@ The project can be deployed in a production environment following Symfony's depl
Comprehensive documentation is available in the `/docs/` directory, including installation instructions, configuration guides, and operational procedures.
This documentation is written using the mkdocs tool.
## Development Workflow
1. **Create a Feature Branch**: Always create a new branch for your feature or bugfix

View File

@@ -47,7 +47,7 @@ class Gender
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::FLOAT, name: 'ordering', nullable: true, options: ['default' => '0.0'])]
private float $order = 0;
public function getId(): int
public function getId(): ?int
{
return $this->id;
}

View File

@@ -186,6 +186,6 @@ class AccompanyingPeriodDocGenNormalizer implements NormalizerInterface, Normali
public function getSupportedTypes(?string $format): array
{
return 'docgen' === $format ? [AccompanyingPeriod::class => true] : [];
return 'docgen' === $format ? [AccompanyingPeriod::class => true, '*' => false] : [];
}
}

View File

@@ -34,13 +34,12 @@ class GenderDocGenNormalizer implements NormalizerInterface, NormalizerAwareInte
'id' => $gender->getId(),
'label' => $this->translatableStringHelper->localize($gender->getLabel()),
'genderTranslation' => $gender->getGenderTranslation(),
'isNull' => false,
];
}
public function getSupportedTypes(?string $format): array
{
return [
Gender::class => true,
];
return 'docgen' === $format ? [Gender::class => true, '*' => false] : [];
}
}

View File

@@ -76,7 +76,7 @@ class PersonDocGenNormalizer implements
return $this->normalizeNullValue($format, $context);
}
$data = [
$result = [
'type' => 'person',
'id' => $data->getId(),
'isNull' => false,
@@ -113,7 +113,7 @@ class PersonDocGenNormalizer implements
];
if ($context['docgen:person:with-household'] ?? false) {
$data['household'] = $this->normalizer->normalize(
$result['household'] = $this->normalizer->normalize(
$data->getCurrentHousehold(),
$format,
array_merge($context, [
@@ -126,7 +126,7 @@ class PersonDocGenNormalizer implements
}
if ($context['docgen:person:with-relations'] ?? false) {
$data['relations'] = $this->normalizer->normalize(
$result['relations'] = $this->normalizer->normalize(
new ArrayCollection($this->relationshipRepository->findByPerson($data)),
$format,
array_merge($context, [
@@ -139,14 +139,14 @@ class PersonDocGenNormalizer implements
}
if ($context['docgen:person:with-budget'] ?? false) {
$data['budget']['person'] = $this->summaryBudget->getSummaryForPerson($data);
$result['budget']['person'] = $this->summaryBudget->getSummaryForPerson($data);
if ($context['docgen:person:with-household'] ?? false) {
$data['budget']['household'] = $this->summaryBudget->getSummaryForHousehold($data->getCurrentHousehold());
$result['budget']['household'] = $this->summaryBudget->getSummaryForHousehold($data->getCurrentHousehold());
}
}
return $data;
return $result;
}
public function supportsNormalization($data, $format = null, array $context = []): bool
@@ -249,6 +249,6 @@ class PersonDocGenNormalizer implements
public function getSupportedTypes(?string $format): array
{
return 'docgen' === $format ? [Person::class => true] : [];
return 'docgen' === $format ? [Person::class => true, '*' => false] : [];
}
}

View File

@@ -86,6 +86,6 @@ class RelationshipDocGenNormalizer implements NormalizerInterface, NormalizerAwa
public function getSupportedTypes(?string $format): array
{
return 'docgen' === $format ? [Relationship::class => true] : [];
return 'docgen' === $format ? [Relationship::class => true, '*' => false] : [];
}
}

View File

@@ -94,12 +94,10 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte
public function getSupportedTypes(?string $format): array
{
if ('json' === $format || 'docgen' === $format) {
return [
SocialAction::class => true,
];
}
return [];
return match ($format) {
'json' => [SocialAction::class => true],
'docgen' => [SocialAction::class => true, '*' => false],
default => [],
};
}
}

View File

@@ -75,12 +75,10 @@ class SocialIssueNormalizer implements NormalizerInterface, NormalizerAwareInter
public function getSupportedTypes(?string $format): array
{
if ('json' === $format || 'docgen' === $format) {
return [
SocialIssue::class => true,
];
}
return [];
return match ($format) {
'json' => [SocialIssue::class => true],
'docgen' => [SocialIssue::class => true, '*' => false],
default => [],
};
}
}

View File

@@ -11,11 +11,11 @@ declare(strict_types=1);
namespace Serializer\Normalizer;
use Chill\DocGeneratorBundle\Test\DocGenNormalizerTestAbstract;
use Chill\MainBundle\Entity\Scope;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
@@ -23,9 +23,36 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
*
* @coversNothing
*/
final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
final class AccompanyingPeriodDocGenNormalizerTest extends DocGenNormalizerTestAbstract
{
private NormalizerInterface $normalizer;
protected NormalizerInterface $normalizer;
protected function getNormalizer(): NormalizerInterface
{
return $this->normalizer;
}
public function provideNotNullObject(): object
{
$period = new AccompanyingPeriod();
$period->setConfidential(true);
$period->setEmergency(true);
$period->setOrigin(new AccompanyingPeriod\Origin()->setLabel(['fr' => 'origin']));
$period->setClosingMotive(new AccompanyingPeriod\ClosingMotive()->setName(['closing']));
$period->addScope(new Scope()->setName(['fr' => 'scope1']));
$period->addScope(new Scope()->setName(['fr' => 'scope2']));
$period->addSocialIssue(new SocialIssue()->setTitle(['fr' => 'issue1']));
$period->addSocialIssue(new SocialIssue()->setTitle(['fr' => 'issue2']));
$period->addPerson(new Person());
$period->addPerson(new Person());
return $period;
}
public function provideDocGenExpectClass(): string
{
return AccompanyingPeriod::class;
}
protected function setUp(): void
{

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\PersonBundle\Tests\Serializer\Normalizer;
use Chill\DocGeneratorBundle\Test\DocGenNormalizerTestAbstract;
use Chill\MainBundle\Entity\Gender;
use Chill\MainBundle\Entity\GenderEnum;
use Chill\MainBundle\Entity\GenderIconEnum;
/**
* @internal
*
* @coversNothing
*/
class GenderDocGenNormalizerTest extends DocGenNormalizerTestAbstract
{
public function provideNotNullObject(): object
{
$gender = new Gender();
$gender->setLabel(['fr' => 'gender']);
$gender->setGenderTranslation(GenderEnum::FEMALE);
$gender->setIcon(GenderIconEnum::AMBIGUOUS);
return $gender;
}
public function provideDocGenExpectClass(): string
{
return Gender::class;
}
}

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Serializer\Normalizer;
use Chill\BudgetBundle\Service\Summary\SummaryBudgetInterface;
use Chill\DocGeneratorBundle\Test\DocGenNormalizerTestAbstract;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Household\Household;
@@ -25,7 +26,6 @@ use Chill\PersonBundle\Serializer\Normalizer\PersonDocGenNormalizer;
use Chill\PersonBundle\Templating\Entity\PersonRender;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -34,7 +34,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*
* @coversNothing
*/
final class PersonDocGenNormalizerTest extends KernelTestCase
final class PersonDocGenNormalizerTest extends DocGenNormalizerTestAbstract
{
use ProphecyTrait;
@@ -68,7 +68,47 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
'center' => '@ignored',
];
private NormalizerInterface $normalizer;
protected NormalizerInterface $normalizer;
protected function getNormalizer(): NormalizerInterface
{
return $this->normalizer;
}
public function provideNotNullObject(): object
{
$household = new Household();
$person = new Person();
$person
->setFirstName('Renaud')
->setLastName('Mégane');
$householdMember = new HouseholdMember();
$householdMember
->setPosition(new Position()->setAllowHolder(true)->setLabel(['fr' => 'position'])
->setShareHousehold(true))
->setHolder(true);
$person->addHouseholdParticipation($householdMember);
$household->addMember($householdMember);
$person = new Person();
$person
->setFirstName('Citroen')
->setLastName('Xsara');
$householdMember = new HouseholdMember();
$householdMember
->setPosition(new Position()->setAllowHolder(true)->setLabel(['fr' => 'position2'])
->setShareHousehold(true))
->setHolder(false);
$person->addHouseholdParticipation($householdMember);
$household->addMember($householdMember);
return $person;
}
public function provideDocGenExpectClass(): string
{
return Person::class;
}
protected function setUp(): void
{

View File

@@ -11,12 +11,12 @@ declare(strict_types=1);
namespace Serializer\Normalizer;
use Chill\DocGeneratorBundle\Test\DocGenNormalizerTestAbstract;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Relationships\Relation;
use Chill\PersonBundle\Entity\Relationships\Relationship;
use Chill\PersonBundle\Serializer\Normalizer\RelationshipDocGenNormalizer;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@@ -26,10 +26,30 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
*
* @coversNothing
*/
final class RelationshipDocGenNormalizerTest extends TestCase
final class RelationshipDocGenNormalizerTest extends DocGenNormalizerTestAbstract
{
use ProphecyTrait;
public function provideNotNullObject(): object
{
$relationship = new Relationship();
$relationship
->setFromPerson($person1 = new Person())
->setToPerson($person2 = new Person())
->setRelation(
new Relation()->setTitle(['fr' => 'title'])
->setReverseTitle(['fr' => 'reverse title'])
)
->setReverse(false);
return $relationship;
}
public function provideDocGenExpectClass(): string
{
return Relationship::class;
}
public function testNormalizeRelationshipNull(): void
{
$relationship = null;

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\PersonBundle\Tests\Serializer\Normalizer;
use Chill\DocGeneratorBundle\Test\DocGenNormalizerTestAbstract;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
/**
* @internal
*
* @coversNothing
*/
class SocialActionDocGenNormalizerTest extends DocGenNormalizerTestAbstract
{
public function provideNotNullObject(): object
{
$action = new SocialAction();
$action->setTitle(['fr' => 'my action']);
$action->setIssue(new SocialIssue());
return $action;
}
public function provideDocGenExpectClass(): string
{
return SocialAction::class;
}
}

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/*
* 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.
*/
namespace Chill\PersonBundle\Tests\Serializer\Normalizer;
use Chill\DocGeneratorBundle\Test\DocGenNormalizerTestAbstract;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
/**
* @internal
*
* @coversNothing
*/
class SocialIssueDocGenNormalizerTest extends DocGenNormalizerTestAbstract
{
public function provideNotNullObject(): object
{
$issue = new SocialIssue();
$issue->setTitle(['fr' => 'my issue']);
return $issue;
}
public function provideDocGenExpectClass(): string
{
return SocialIssue::class;
}
}