This commit is contained in:
2021-12-06 17:27:57 +01:00
parent 25147704ad
commit ebd817f61e
9 changed files with 52 additions and 46 deletions

View File

@@ -11,7 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity;
use DateTimeImmutable;
use DateTime;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
@@ -38,7 +38,7 @@ class AccompanyingPeriodParticipation
* @ORM\Column(type="date", nullable=true)
* @Groups({"read", "docgen:read"})
*/
private ?\DateTime $endDate = null;
private ?DateTime $endDate = null;
/**
* @ORM\Id
@@ -59,11 +59,11 @@ class AccompanyingPeriodParticipation
* @ORM\Column(type="date", nullable=false)
* @Groups({"read", "docgen:read"})
*/
private ?\DateTime $startDate = null;
private ?DateTime $startDate = null;
public function __construct(AccompanyingPeriod $accompanyingPeriod, Person $person)
{
$this->startDate = new \DateTime('now');
$this->startDate = new DateTime('now');
$this->accompanyingPeriod = $accompanyingPeriod;
$this->person = $person;
}

View File

@@ -157,8 +157,6 @@ class Household
}
/**
* @param DateTimeImmutable|null $now
* @return Collection
* @Serializer\Groups({"docgen:read"})
*/
public function getCurrentMembers(?DateTimeImmutable $now = null): Collection

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
@@ -41,8 +40,8 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte
'desactivationDate' => $this->normalizer->normalize($socialAction->getDesactivationDate()),
'title' => $socialAction->getTitle(),
];
case 'docgen':
case 'docgen':
if (null === $socialAction) {
return ['id' => 0, 'title' => '', 'text' => ''];
}
@@ -52,12 +51,13 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte
'text' => $this->render->renderString($socialAction, []),
'title' => $socialAction->getTitle(),
];
default:
throw new \Symfony\Component\Serializer\Exception\RuntimeException("format not supported");
throw new \Symfony\Component\Serializer\Exception\RuntimeException('format not supported');
}
}
public function supportsNormalization($data, string $format = null, array $context = [])
public function supportsNormalization($data, ?string $format = null, array $context = [])
{
if ($data instanceof SocialAction && 'json' === $format) {
return true;
@@ -68,7 +68,7 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte
return true;
}
if (null === $data && ($context['docgen:expects'] ?? null) === SocialAction::class) {
if (null === $data && SocialAction::class === ($context['docgen:expects'] ?? null)) {
return true;
}
}

View File

@@ -16,9 +16,8 @@ use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class SocialIssueNormalizer implements NormalizerAwareInterface, ContextAwareNormalizerInterface
class SocialIssueNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
{
use NormalizerAwareTrait;
@@ -42,8 +41,8 @@ class SocialIssueNormalizer implements NormalizerAwareInterface, ContextAwareNor
'title' => $socialIssue->getTitle(),
'text' => $this->render->renderString($socialIssue, []),
];
case 'docgen':
case 'docgen':
if (null === $socialIssue) {
return ['id' => 0, 'title' => '', 'text' => ''];
}
@@ -56,20 +55,20 @@ class SocialIssueNormalizer implements NormalizerAwareInterface, ContextAwareNor
}
}
public function supportsNormalization($data, string $format = null, array $context = [])
public function supportsNormalization($data, ?string $format = null, array $context = [])
{
if ($data instanceof SocialIssue && 'json' === $format) {
return true;
}
if ('docgen' === $format) {
if ($data instanceof SocialIssue) {
return true;
}
if ($data instanceof SocialIssue) {
return true;
}
if (null === $data && ($context['docgen:expects'] ?? null) === SocialIssue::class) {
return true;
}
if (null === $data && SocialIssue::class === ($context['docgen:expects'] ?? null)) {
return true;
}
}
return false;

View File

@@ -80,22 +80,6 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
}
}
public function testNormalizeParticipations()
{
$period = new AccompanyingPeriod();
$period->addPerson($person = new Person());
$person->setFirstName('test');
$data = $this->normalizer->normalize($period, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
$this->assertIsArray($data);
$this->assertArrayHasKey('participations', $data);
$this->assertCount(1, $data['participations']);
$this->assertArrayHasKey('currentParticipations', $data);
$this->assertCount(1, $data['currentParticipations']);
}
public function testNormalizeNull()
{
$data = $this->normalizer->normalize(null, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
@@ -134,4 +118,20 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
$this->assertEquals($item, $data[$key]);
}
}
public function testNormalizeParticipations()
{
$period = new AccompanyingPeriod();
$period->addPerson($person = new Person());
$person->setFirstName('test');
$data = $this->normalizer->normalize($period, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
$this->assertIsArray($data);
$this->assertArrayHasKey('participations', $data);
$this->assertCount(1, $data['participations']);
$this->assertArrayHasKey('currentParticipations', $data);
$this->assertCount(1, $data['currentParticipations']);
}
}