Use Person::centerHistory to load fixtures with given center

This commit is contained in:
Julien Fastré 2023-07-28 01:22:55 +02:00
parent 0e94e769cb
commit 6f2b538e27
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
5 changed files with 28 additions and 21 deletions

View File

@ -82,8 +82,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
->findOneBy(['name' => 'Center A']); ->findOneBy(['name' => 'Center A']);
$personIds = $em->createQuery('SELECT p.id FROM ' . $personIds = $em->createQuery('SELECT p.id FROM ' .
Person::class . ' p ' . Person::class . ' p JOIN p.centerCurrent cc' .
' WHERE p.center = :center') ' WHERE cc.center = :center')
->setParameter('center', $center) ->setParameter('center', $center)
->setMaxResults(100) ->setMaxResults(100)
->getScalarResult(); ->getScalarResult();
@ -127,9 +127,10 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
->from(Person::class, 'p') ->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'participation') ->join('p.accompanyingPeriodParticipations', 'participation')
->join('participation.accompanyingPeriod', 'ap') ->join('participation.accompanyingPeriod', 'ap')
->join('p.centerCurrent', 'cc')
->where( ->where(
$qb->expr()->eq( $qb->expr()->eq(
'p.center', 'cc.center',
':center' ':center'
) )
) )
@ -191,9 +192,10 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
->from(Person::class, 'p') ->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'participation') ->join('p.accompanyingPeriodParticipations', 'participation')
->join('participation.accompanyingPeriod', 'ap') ->join('participation.accompanyingPeriod', 'ap')
->join('p.centerCurrent', 'cc')
->where( ->where(
$qb->expr()->eq( $qb->expr()->eq(
'p.center', 'cc.center',
':center' ':center'
) )
) )
@ -252,9 +254,10 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
->from(Person::class, 'p') ->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'participation') ->join('p.accompanyingPeriodParticipations', 'participation')
->join('participation.accompanyingPeriod', 'ap') ->join('participation.accompanyingPeriod', 'ap')
->join('p.centerCurrent', 'cc')
->where( ->where(
$qb->expr()->eq( $qb->expr()->eq(
'p.center', 'cc.center',
':center' ':center'
) )
) )

View File

@ -104,7 +104,8 @@ final class HouseholdApiControllerTest extends WebTestCase
->from(Household::class, 'household') ->from(Household::class, 'household')
->join('household.members', 'members') ->join('household.members', 'members')
->join('members.person', 'person') ->join('members.person', 'person')
->join('person.center', 'center') ->join('person.centerCurrent', 'cc')
->join('cc.center', 'center')
->where($qb->expr()->eq('center.name', ':center_name')) ->where($qb->expr()->eq('center.name', ':center_name'))
->andWhere($qb->expr()->gt('SIZE(person.accompanyingPeriodParticipations)', 0)) ->andWhere($qb->expr()->gt('SIZE(person.accompanyingPeriodParticipations)', 0))
->setParameter('center_name', 'Center A') ->setParameter('center_name', 'Center A')

View File

@ -43,16 +43,16 @@ final class HouseholdControllerTest extends WebTestCase
$em = self::$container->get(EntityManagerInterface::class); $em = self::$container->get(EntityManagerInterface::class);
$ids = $em->createQuery( $ids = $em->createQuery(
'SELECT DISTINCT h.id FROM ' . Household::class . ' h ' . sprintf("SELECT DISTINCT h.id FROM %s h JOIN h.members m JOIN m.person p JOIN p.centerHistory ch JOIN ch.center c WHERE c.name = :center AND ch.endDate IS NULL", Household::class)
'JOIN h.members m ' .
'JOIN m.person p ' .
'JOIN p.center c ' .
'WHERE c.name = :center'
) )
->setParameter('center', 'Center A') ->setParameter('center', 'Center A')
->setMaxResults(100) ->setMaxResults(100)
->getScalarResult(); ->getScalarResult();
if ([] === $ids) {
throw new \RuntimeException('no household ids with center "Center A"');
}
shuffle($ids); shuffle($ids);
yield [array_pop($ids)['id']]; yield [array_pop($ids)['id']];

View File

@ -43,13 +43,14 @@ final class HouseholdMemberControllerTest extends WebTestCase
self::bootKernel(); self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class); $em = self::$container->get(EntityManagerInterface::class);
$membershipIds = $em->createQuery('SELECT m.id FROM ' . HouseholdMember::class . ' m ' . $membershipIds = $em->createQuery(sprintf("SELECT m.id FROM %s m JOIN m.person p JOIN p.centerHistory ch JOIN ch.center c WHERE c.name = :center AND m.endDate IS NULL AND ch.endDate IS NULL", HouseholdMember::class))
'JOIN m.person p ' .
'JOIN p.center c ' .
'WHERE c.name = :center AND m.endDate IS NULL')
->setParameter('center', 'Center A') ->setParameter('center', 'Center A')
->getScalarResult(); ->getScalarResult();
if ([] === $membershipIds) {
throw new \RuntimeException("no memberships for person associated to 'Center A'");
}
shuffle($membershipIds); shuffle($membershipIds);
yield [array_pop($membershipIds)['id']]; yield [array_pop($membershipIds)['id']];
@ -62,15 +63,16 @@ final class HouseholdMemberControllerTest extends WebTestCase
$yesterday = new DateTimeImmutable('yesterday'); $yesterday = new DateTimeImmutable('yesterday');
$personIds = $em->createQuery( $personIds = $em->createQuery(
'SELECT p.id FROM ' . Person::class . ' p ' . sprintf("SELECT p.id FROM %s p JOIN p.centerHistory ch JOIN ch.center c WHERE c.name = :center AND ch.endDate IS NULL", Person::class)
'JOIN p.center c ' .
'WHERE ' .
'c.name = :center '
) )
->setParameter('center', 'Center A') ->setParameter('center', 'Center A')
->setMaxResults(100) ->setMaxResults(100)
->getScalarResult(); ->getScalarResult();
if ([] === $personIds) {
throw new \RuntimeException('no person associated with "Center A"');
}
shuffle($personIds); shuffle($personIds);
$household = new Household(); $household = new Household();
@ -111,7 +113,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
/** /**
* @dataProvider provideValidDataEditMember * @dataProvider provideValidDataEditMember
*/ */
public function testEditMember(mixed $memberId) public function testEditMember(int $memberId)
{ {
$client = $this->getClientAuthenticated(); $client = $this->getClientAuthenticated();

View File

@ -39,7 +39,8 @@ final class TimelineAccompanyingPeriodTest extends WebTestCase
->from(Person::class, 'p') ->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'part') ->join('p.accompanyingPeriodParticipations', 'part')
->join('part.accompanyingPeriod', 'period') ->join('part.accompanyingPeriod', 'period')
->join('p.center', 'center') ->join('p.centerCurrent', 'cc')
->join('cc.center', 'center')
->select('p.id') ->select('p.id')
->where($qb->expr()->eq('center.name', ':center')) ->where($qb->expr()->eq('center.name', ':center'))
->setParameter('center', 'Center A') ->setParameter('center', 'Center A')