mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
docgen normalization for relation
This commit is contained in:
parent
119a9981af
commit
2524229941
@ -24,6 +24,8 @@ class RelationshipRepository implements ObjectRepository
|
|||||||
|
|
||||||
private EntityRepository $repository;
|
private EntityRepository $repository;
|
||||||
|
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
$this->repository = $em->getRepository(Relationship::class);
|
$this->repository = $em->getRepository(Relationship::class);
|
||||||
@ -64,6 +66,30 @@ class RelationshipRepository implements ObjectRepository
|
|||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function countByPerson(Person $person): int
|
||||||
|
{
|
||||||
|
return $this->buildQueryByPerson($person)
|
||||||
|
->select('COUNT(p)')
|
||||||
|
->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildQueryByPerson(Person $person): QueryBuilder
|
||||||
|
{
|
||||||
|
$qb = $this->em->createQueryBuilder();
|
||||||
|
$qb
|
||||||
|
->from(Relationship::class, 'r')
|
||||||
|
->where(
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->eq('r.fromPerson', ':person'),
|
||||||
|
$qb->expr()->eq('r.toPerson', ':person')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setParameter('person', $person);
|
||||||
|
|
||||||
|
return $qb;
|
||||||
|
}
|
||||||
|
|
||||||
public function findOneBy(array $criteria): ?Relationship
|
public function findOneBy(array $criteria): ?Relationship
|
||||||
{
|
{
|
||||||
return $this->findOneBy($criteria);
|
return $this->findOneBy($criteria);
|
||||||
|
@ -60,6 +60,38 @@ 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