mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
test "find household by reference": add exception in data provider
The data provider cannot generate data if no address reference in database. Throw an exception in this case.
This commit is contained in:
parent
9b4c350213
commit
b5a1985fa1
@ -58,10 +58,16 @@ final class HouseholdApiControllerTest extends WebTestCase
|
|||||||
$centerA = $em->getRepository(Center::class)->findOneBy(['name' => 'Center A']);
|
$centerA = $em->getRepository(Center::class)->findOneBy(['name' => 'Center A']);
|
||||||
$nbReference = $em->createQueryBuilder()->select('count(ar)')->from(AddressReference::class, 'ar')
|
$nbReference = $em->createQueryBuilder()->select('count(ar)')->from(AddressReference::class, 'ar')
|
||||||
->getQuery()->getSingleScalarResult();
|
->getQuery()->getSingleScalarResult();
|
||||||
|
|
||||||
|
if ($nbReference === 0) {
|
||||||
|
throw new \RuntimeException('any reference found. Add a reference in database to perform this test');
|
||||||
|
}
|
||||||
|
|
||||||
$reference = $em->createQueryBuilder()->select('ar')->from(AddressReference::class, 'ar')
|
$reference = $em->createQueryBuilder()->select('ar')->from(AddressReference::class, 'ar')
|
||||||
->setFirstResult(random_int(0, $nbReference))
|
->setFirstResult(random_int(0, $nbReference))
|
||||||
->setMaxResults(1)
|
->setMaxResults(1)
|
||||||
->getQuery()->getSingleResult();
|
->getQuery()->getSingleResult();
|
||||||
|
|
||||||
$p = new Person();
|
$p = new Person();
|
||||||
$p->setFirstname('test')->setLastName('test lastname')
|
$p->setFirstname('test')->setLastName('test lastname')
|
||||||
->setGender(Person::BOTH_GENDER)
|
->setGender(Person::BOTH_GENDER)
|
||||||
@ -79,6 +85,7 @@ final class HouseholdApiControllerTest extends WebTestCase
|
|||||||
[HouseholdMember::class, $m->getId()],
|
[HouseholdMember::class, $m->getId()],
|
||||||
[User::class, $p->getId()],
|
[User::class, $p->getId()],
|
||||||
[Household::class, $h->getId()],
|
[Household::class, $h->getId()],
|
||||||
|
[Person::class, $p->getId()],
|
||||||
];
|
];
|
||||||
|
|
||||||
yield [$reference->getId(), $h->getId()];
|
yield [$reference->getId(), $h->getId()];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user