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']);
$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'
)
)

View File

@ -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')

View File

@ -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']];

View File

@ -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();

View File

@ -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')