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

@@ -44,6 +44,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
/**
* @see AccompanyingPeriodContextTest
* @template-implements DocGeneratorContextWithPublicFormInterface<AccompanyingPeriod>
*/
class AccompanyingPeriodContext implements
@@ -116,12 +117,11 @@ class AccompanyingPeriodContext implements
'person2' => $data['person2'] ?? false,
'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'),
'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;
@@ -214,17 +214,15 @@ class AccompanyingPeriodContext implements
}
$thirdParties = array_merge(
array_filter(array_values([$entity->getRequestorThirdParty()])),
array_filter(
array_values(
array_map(
fn (Resource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getResources()->filter(
static fn (Resource $r): bool => null !== $r->getThirdParty()
)->toArray()
)
array_values(array_filter([$entity->getRequestorThirdParty()])),
array_values(array_filter(
array_map(
fn (Resource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getResources()->filter(
static fn (Resource $r): bool => null !== $r->getThirdParty()
)->toArray()
)
)
))
);
if ($options['thirdParty'] ?? false) {
@@ -320,7 +318,7 @@ class AccompanyingPeriodContext implements
$normalized[$k] = null !== ($data[$k] ?? null) ? $data[$k]->getId() : null;
}
$normalized['thirdParty'] = null === $data['thirdParty'] ? null : $data['thirdParty']->getId();
$normalized['thirdParty'] = ($data['thirdParty'] ?? null)?->getId();
return $normalized;
}