mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add docgen:normalization for relation
This commit is contained in:
parent
2524229941
commit
a25123ee38
@ -268,6 +268,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
->localize($value);
|
->localize($value);
|
||||||
} elseif (is_iterable($value)) {
|
} elseif (is_iterable($value)) {
|
||||||
$arr = [];
|
$arr = [];
|
||||||
|
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
$arr[$k] =
|
$arr[$k] =
|
||||||
$this->normalizer->normalize($v, $format, array_merge(
|
$this->normalizer->normalize($v, $format, array_merge(
|
||||||
|
@ -26,6 +26,8 @@ class RelationshipRepository implements ObjectRepository
|
|||||||
|
|
||||||
private EntityManagerInterface $em;
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
|
private EntityRepository $repository;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
$this->repository = $em->getRepository(Relationship::class);
|
$this->repository = $em->getRepository(Relationship::class);
|
||||||
@ -66,12 +68,14 @@ class RelationshipRepository implements ObjectRepository
|
|||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function countByPerson(Person $person): int
|
public function findOneBy(array $criteria): ?Relationship
|
||||||
{
|
{
|
||||||
return $this->buildQueryByPerson($person)
|
return $this->findOneBy($criteria);
|
||||||
->select('COUNT(p)')
|
}
|
||||||
->getQuery()
|
|
||||||
->getSingleScalarResult();
|
public function getClassName(): string
|
||||||
|
{
|
||||||
|
return Relationship::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildQueryByPerson(Person $person): QueryBuilder
|
private function buildQueryByPerson(Person $person): QueryBuilder
|
||||||
|
@ -60,38 +60,6 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
|||||||
|
|
||||||
private NormalizerInterface $normalizer;
|
private NormalizerInterface $normalizer;
|
||||||
|
|
||||||
private function buildPersonNormalizer(
|
|
||||||
?PersonRender $personRender = null,
|
|
||||||
?RelationshipRepository $relationshipRepository = null,
|
|
||||||
?TranslatorInterface $translator = null,
|
|
||||||
?TranslatableStringHelper $translatableStringHelper = null
|
|
||||||
): PersonDocGenNormalizer {
|
|
||||||
$normalizer = new PersonDocGenNormalizer(
|
|
||||||
$personRender ?? self::$container->get(PersonRender::class),
|
|
||||||
$relationshipRepository ?? self::$container->get(RelationshipRepository::class),
|
|
||||||
$translator ??self::$container->get(TranslatorInterface::class),
|
|
||||||
$translatableStringHelper ?? self::$container->get(TranslatableStringHelperInterface::class)
|
|
||||||
);
|
|
||||||
$normalizerManager = $this->prophesize(NormalizerInterface::class);
|
|
||||||
$normalizerManager->supportsNormalization(Argument::any(), 'docgen', Argument::any())->willReturn(true);
|
|
||||||
$normalizerManager->normalize(Argument::type(Person::class), 'docgen', Argument::any())
|
|
||||||
->will(function($args) use ($normalizer) {
|
|
||||||
return $normalizer->normalize($args[0], $args[1], $args[2]);
|
|
||||||
});
|
|
||||||
$normalizerManager->normalize(Argument::any(), 'docgen', Argument::any())->will(
|
|
||||||
function ($args) {
|
|
||||||
if (is_iterable($args[0])) {
|
|
||||||
$r = [];
|
|
||||||
foreach ($args[0] as $i) { $r[] = ['fake' => true, 'hash' => spl_object_hash($i)];}
|
|
||||||
return $r;
|
|
||||||
}
|
|
||||||
return ['fake' => true, 'hash' => null !== $args[0] ? spl_object_hash($args[0]) : null];
|
|
||||||
});
|
|
||||||
$normalizer->setNormalizer($normalizerManager->reveal());
|
|
||||||
|
|
||||||
return $normalizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user