mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add docgen context for AccompanyingPeriodWork
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Goal;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
class AccompanyingPeriodWorkDocGenNormalizerTest extends KernelTestCase
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::bootKernel();
|
||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||
}
|
||||
|
||||
public function testNormlalize()
|
||||
{
|
||||
$work = new AccompanyingPeriodWork();
|
||||
$work
|
||||
->addPerson((new Person())->setFirstName('hello')->setLastName('name'))
|
||||
->addGoal($g = new AccompanyingPeriodWorkGoal())
|
||||
->addResult($r = new Result())
|
||||
->setCreatedAt(new \DateTimeImmutable())
|
||||
->setUpdatedAt(new \DateTimeImmutable())
|
||||
->setCreatedBy($user = new User())
|
||||
->setUpdatedBy($user)
|
||||
;
|
||||
$g->addResult($r)->setGoal($goal = new Goal());
|
||||
$goal->addResult($r);
|
||||
|
||||
$actual = $this->normalizer->normalize($work, 'docgen', [
|
||||
'docgen:expects' => AccompanyingPeriodWork::class,
|
||||
AbstractNormalizer::GROUPS => ['docgen:read']
|
||||
]);
|
||||
|
||||
var_dump($actual);
|
||||
|
||||
$expected = [
|
||||
'id' => 0,
|
||||
|
||||
];
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
|
||||
|
||||
foreach ($expected as $key => $item) {
|
||||
if ('@ignored' === $item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertEquals($item, $actual[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testNormalizationNull()
|
||||
{
|
||||
$actual = $this->normalizer->normalize(null, 'docgen', [
|
||||
'docgen:expects' => AccompanyingPeriodWork::class,
|
||||
AbstractNormalizer::GROUPS => ['docgen:read']
|
||||
]);
|
||||
|
||||
dump($actual);
|
||||
|
||||
$expected = [
|
||||
'id' => ""
|
||||
];
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
|
||||
|
||||
foreach ($expected as $key => $item) {
|
||||
if ('@ignored' === $item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertEquals($item, $actual[$key]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user