From 6f2b538e27544c8ebf094ebed10429f80a44a507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 28 Jul 2023 01:22:55 +0200 Subject: [PATCH] Use `Person::centerHistory` to load fixtures with given center --- .../AccompanyingCourseApiControllerTest.php | 13 +++++++----- .../Controller/HouseholdApiControllerTest.php | 3 ++- .../Controller/HouseholdControllerTest.php | 10 +++++----- .../HouseholdMemberControllerTest.php | 20 ++++++++++--------- .../TimelineAccompanyingPeriodTest.php | 3 ++- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php index 60d29d8b0..574c8cc64 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php @@ -82,8 +82,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase ->findOneBy(['name' => 'Center A']); $personIds = $em->createQuery('SELECT p.id FROM ' . - Person::class . ' p ' . - ' WHERE p.center = :center') + Person::class . ' p JOIN p.centerCurrent cc' . + ' WHERE cc.center = :center') ->setParameter('center', $center) ->setMaxResults(100) ->getScalarResult(); @@ -127,9 +127,10 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase ->from(Person::class, 'p') ->join('p.accompanyingPeriodParticipations', 'participation') ->join('participation.accompanyingPeriod', 'ap') + ->join('p.centerCurrent', 'cc') ->where( $qb->expr()->eq( - 'p.center', + 'cc.center', ':center' ) ) @@ -191,9 +192,10 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase ->from(Person::class, 'p') ->join('p.accompanyingPeriodParticipations', 'participation') ->join('participation.accompanyingPeriod', 'ap') + ->join('p.centerCurrent', 'cc') ->where( $qb->expr()->eq( - 'p.center', + 'cc.center', ':center' ) ) @@ -252,9 +254,10 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase ->from(Person::class, 'p') ->join('p.accompanyingPeriodParticipations', 'participation') ->join('participation.accompanyingPeriod', 'ap') + ->join('p.centerCurrent', 'cc') ->where( $qb->expr()->eq( - 'p.center', + 'cc.center', ':center' ) ) diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdApiControllerTest.php index f01eeeaa9..10a571728 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdApiControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdApiControllerTest.php @@ -104,7 +104,8 @@ final class HouseholdApiControllerTest extends WebTestCase ->from(Household::class, 'household') ->join('household.members', 'members') ->join('members.person', 'person') - ->join('person.center', 'center') + ->join('person.centerCurrent', 'cc') + ->join('cc.center', 'center') ->where($qb->expr()->eq('center.name', ':center_name')) ->andWhere($qb->expr()->gt('SIZE(person.accompanyingPeriodParticipations)', 0)) ->setParameter('center_name', 'Center A') diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdControllerTest.php index 5cc3d0643..93ec2f4a5 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdControllerTest.php @@ -43,16 +43,16 @@ final class HouseholdControllerTest extends WebTestCase $em = self::$container->get(EntityManagerInterface::class); $ids = $em->createQuery( - 'SELECT DISTINCT h.id FROM ' . Household::class . ' h ' . - 'JOIN h.members m ' . - 'JOIN m.person p ' . - 'JOIN p.center c ' . - 'WHERE c.name = :center' + 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) ) ->setParameter('center', 'Center A') ->setMaxResults(100) ->getScalarResult(); + if ([] === $ids) { + throw new \RuntimeException('no household ids with center "Center A"'); + } + shuffle($ids); yield [array_pop($ids)['id']]; diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdMemberControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdMemberControllerTest.php index 4986d5b9a..bb700602f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdMemberControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdMemberControllerTest.php @@ -43,13 +43,14 @@ final class HouseholdMemberControllerTest extends WebTestCase self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); - $membershipIds = $em->createQuery('SELECT m.id FROM ' . HouseholdMember::class . ' m ' . - 'JOIN m.person p ' . - 'JOIN p.center c ' . - 'WHERE c.name = :center AND m.endDate IS NULL') + $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)) ->setParameter('center', 'Center A') ->getScalarResult(); + if ([] === $membershipIds) { + throw new \RuntimeException("no memberships for person associated to 'Center A'"); + } + shuffle($membershipIds); yield [array_pop($membershipIds)['id']]; @@ -62,15 +63,16 @@ final class HouseholdMemberControllerTest extends WebTestCase $yesterday = new DateTimeImmutable('yesterday'); $personIds = $em->createQuery( - 'SELECT p.id FROM ' . Person::class . ' p ' . - 'JOIN p.center c ' . - 'WHERE ' . - 'c.name = :center ' + 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) ) ->setParameter('center', 'Center A') ->setMaxResults(100) ->getScalarResult(); + if ([] === $personIds) { + throw new \RuntimeException('no person associated with "Center A"'); + } + shuffle($personIds); $household = new Household(); @@ -111,7 +113,7 @@ final class HouseholdMemberControllerTest extends WebTestCase /** * @dataProvider provideValidDataEditMember */ - public function testEditMember(mixed $memberId) + public function testEditMember(int $memberId) { $client = $this->getClientAuthenticated(); diff --git a/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php b/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php index 7560b8fb1..ce372c49e 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Timeline/TimelineAccompanyingPeriodTest.php @@ -39,7 +39,8 @@ final class TimelineAccompanyingPeriodTest extends WebTestCase ->from(Person::class, 'p') ->join('p.accompanyingPeriodParticipations', 'part') ->join('part.accompanyingPeriod', 'period') - ->join('p.center', 'center') + ->join('p.centerCurrent', 'cc') + ->join('cc.center', 'center') ->select('p.id') ->where($qb->expr()->eq('center.name', ':center')) ->setParameter('center', 'Center A')