mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix tests for person json normalizer and residential address stuff
This commit is contained in:
parent
9769aa1386
commit
4ad65b616d
@ -33,6 +33,7 @@ use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
|
|||||||
use function array_key_exists;
|
use function array_key_exists;
|
||||||
use function count;
|
use function count;
|
||||||
use function in_array;
|
use function in_array;
|
||||||
|
use function is_string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize a Person entity.
|
* Serialize a Person entity.
|
||||||
@ -56,11 +57,11 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
|
|||||||
private ResidentialAddressRepository $residentialAddressRepository;
|
private ResidentialAddressRepository $residentialAddressRepository;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ChillEntityRenderExtension $render,
|
ChillEntityRenderExtension $render, /* TODO: replace by PersonRenderInterface, as sthis is the only one required */
|
||||||
PersonRepository $repository,
|
PersonRepository $repository,
|
||||||
CenterResolverManagerInterface $centerResolverManager,
|
CenterResolverManagerInterface $centerResolverManager,
|
||||||
ResidentialAddressRepository $residentialAddressRepository,
|
ResidentialAddressRepository $residentialAddressRepository,
|
||||||
PhoneNumberHelperInterface $phoneNumberHelper
|
PhoneNumberHelperInterface $phoneNumberHelper /* TODO maybe not necessayr any more */
|
||||||
) {
|
) {
|
||||||
$this->render = $render;
|
$this->render = $render;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
@ -189,6 +190,7 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
|
|||||||
public function normalize($person, $format = null, array $context = [])
|
public function normalize($person, $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$groups = $context[AbstractNormalizer::GROUPS] ?? [];
|
$groups = $context[AbstractNormalizer::GROUPS] ?? [];
|
||||||
|
|
||||||
if (is_string($groups)) {
|
if (is_string($groups)) {
|
||||||
$groups = [$groups];
|
$groups = [$groups];
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,15 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Serializer\Normalizer;
|
namespace Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Phonenumber\PhoneNumberHelperInterface;
|
||||||
|
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||||
|
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
|
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
|
||||||
|
use Chill\PersonBundle\Serializer\Normalizer\PersonJsonNormalizer;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
@ -22,12 +30,27 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|||||||
*/
|
*/
|
||||||
final class PersonJsonNormalizerTest extends KernelTestCase
|
final class PersonJsonNormalizerTest extends KernelTestCase
|
||||||
{
|
{
|
||||||
private NormalizerInterface $normalizer;
|
use ProphecyTrait;
|
||||||
|
|
||||||
|
private PersonJsonNormalizer $normalizer;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
|
||||||
|
$residentialAddressRepository = $this->prophesize(ResidentialAddressRepository::class);
|
||||||
|
$residentialAddressRepository
|
||||||
|
->findCurrentResidentialAddressByPerson(Argument::type(Person::class), Argument::any())
|
||||||
|
->willReturn([]);
|
||||||
|
|
||||||
|
$this->normalizer = $this->buildPersonJsonNormalizer(
|
||||||
|
self::$container->get(ChillEntityRenderExtension::class),
|
||||||
|
self::$container->get(PersonRepository::class),
|
||||||
|
self::$container->get(CenterResolverManagerInterface::class),
|
||||||
|
$residentialAddressRepository->reveal(),
|
||||||
|
self::$container->get(PhoneNumberHelperInterface::class),
|
||||||
|
self::$container->get(NormalizerInterface::class)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNormalization()
|
public function testNormalization()
|
||||||
@ -37,4 +60,24 @@ final class PersonJsonNormalizerTest extends KernelTestCase
|
|||||||
|
|
||||||
$this->assertIsArray($result);
|
$this->assertIsArray($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildPersonJsonNormalizer(
|
||||||
|
ChillEntityRenderExtension $render,
|
||||||
|
PersonRepository $repository,
|
||||||
|
CenterResolverManagerInterface $centerResolverManager,
|
||||||
|
ResidentialAddressRepository $residentialAddressRepository,
|
||||||
|
PhoneNumberHelperInterface $phoneNumberHelper,
|
||||||
|
NormalizerInterface $normalizer
|
||||||
|
): PersonJsonNormalizer {
|
||||||
|
$personJsonNormalizer = new PersonJsonNormalizer(
|
||||||
|
$render,
|
||||||
|
$repository,
|
||||||
|
$centerResolverManager,
|
||||||
|
$residentialAddressRepository,
|
||||||
|
$phoneNumberHelper
|
||||||
|
);
|
||||||
|
$personJsonNormalizer->setNormalizer($normalizer);
|
||||||
|
|
||||||
|
return $personJsonNormalizer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user