mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Refactor test to create people without accompanying period on each iteration
This commit is contained in:
parent
2f1f724860
commit
149ed2bd75
@ -52,6 +52,11 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
|
|||||||
|
|
||||||
private static array $periodsIdsToDelete = [];
|
private static array $periodsIdsToDelete = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var list<array<class-string, int>>
|
||||||
|
*/
|
||||||
|
private static array $entitiesToDelete = [];
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
@ -80,7 +85,14 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
|
|||||||
$em->remove($period);
|
$em->remove($period);
|
||||||
}
|
}
|
||||||
|
|
||||||
//$em->flush();
|
foreach (self::$entitiesToDelete as [$class, $id]) {
|
||||||
|
if (null === $entity = $em->find($class, $id)) {
|
||||||
|
throw new \RuntimeException(sprintf("entity %s with id %d not found", $class, $id));
|
||||||
|
}
|
||||||
|
$em->remove($entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
$em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -443,13 +455,23 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
|
|||||||
throw new \RuntimeException("no user found");
|
throw new \RuntimeException("no user found");
|
||||||
}
|
}
|
||||||
|
|
||||||
$persons = $this->entityManager
|
if (null === $centerA = $this->entityManager->createQuery("SELECT c FROM " . Center::class . " c WHERE c.name LIKE :cn")->setParameter('cn', 'Center A')
|
||||||
->createQuery("SELECT p FROM " . Person::class . " p WHERE SIZE(p.accompanyingPeriodParticipations) = 0")
|
->setMaxResults(1)->getSingleResult()) {
|
||||||
->setMaxResults(4)
|
throw new \RuntimeException("Center A not found");
|
||||||
->getResult();
|
}
|
||||||
|
$persons = [new Person(), new Person(), new Person(), new Person()];
|
||||||
|
$firstnames = ['alpha', 'beta', 'gamma', 'delta'];
|
||||||
|
$lastnames = ['primo', 'secundo', 'tertio', 'quartro'];
|
||||||
|
|
||||||
if (4 > count($persons)) {
|
foreach ($persons as $k => $p) {
|
||||||
throw new \RuntimeException("no person found");
|
$p
|
||||||
|
->setFirstName($firstnames[$k])
|
||||||
|
->setLastName($lastnames[$k])
|
||||||
|
->setBirthdate((new \DateTime('today'))->sub(new \DateInterval('P' . random_int(18, 100) . 'Y')))
|
||||||
|
->setCenter($centerA)
|
||||||
|
;
|
||||||
|
$this->entityManager->persist($p);
|
||||||
|
self::$entitiesToDelete[] = [Person::class, $p->getId()];
|
||||||
}
|
}
|
||||||
|
|
||||||
[$person, $anotherPerson, $person2, $person3] = $persons;
|
[$person, $anotherPerson, $person2, $person3] = $persons;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user