fixes: add tests for generation and fix some situation

This commit is contained in:
2023-05-31 23:29:34 +02:00
parent 1b0569c974
commit 80dfa092db
8 changed files with 503 additions and 37 deletions

View File

@@ -38,6 +38,7 @@ use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use LogicException;
use Service\DocGenerator\PersonContextTest;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@@ -50,6 +51,9 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
use function count;
/**
* @see PersonContextTest
*/
final class PersonContext implements PersonContextInterface
{
private AuthorizationHelperInterface $authorizationHelper;
@@ -130,12 +134,11 @@ final class PersonContext implements PersonContextInterface
'mainPerson' => $data['mainPerson'] ?? false,
'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'),
'thirdParty' => $data['thirdParty'] ?? false,
'thirdPartyLabel' => $data['thirdPartyLabel'] ?? $this->translator->trans('thirdParty'),
'thirdPartyLabel' => $data['thirdPartyLabel'] ?? $this->translator->trans('Third party'),
];
if (array_key_exists('category', $data)) {
$r['category'] = array_key_exists('category', $data) ?
$this->documentCategoryRepository->find($data['category']) : null;
$r['category'] = $this->documentCategoryRepository->find($data['category']);
}
return $r;
@@ -177,8 +180,8 @@ final class PersonContext implements PersonContextInterface
]);
$thirdParties = array_merge(
array_filter(
array_values(
array_values(
array_filter(
array_map(
fn (ResidentialAddress $r): ?ThirdParty => $r->getHostThirdParty(),
$this
@@ -187,8 +190,8 @@ final class PersonContext implements PersonContextInterface
)
)
),
array_filter(
array_values(
array_values(
array_filter(
array_map(
fn (PersonResource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getResources()->filter(
@@ -223,10 +226,6 @@ final class PersonContext implements PersonContextInterface
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
{
if (!$entity instanceof Person) {
throw new UnexpectedTypeException($entity, Person::class);
}
$data = [];
$data = array_merge($data, $this->baseContextData->getData($contextGenerationData['creator'] ?? null));
$data['person'] = $this->normalizer->normalize($entity, 'docgen', [
@@ -297,7 +296,7 @@ final class PersonContext implements PersonContextInterface
return [
'title' => $data['title'] ?? '',
'scope_id' => $scope instanceof Scope ? $scope->getId() : null,
'thirdParty' => null === $data['thirdParty'] ? null : $data['thirdParty']->getId(),
'thirdParty' => ($data['thirdParty'] ?? null)?->getId(),
];
}