diff --git a/src/Bundle/ChillPersonBundle/Tests/Repository/AccompanyingPeriodACLAwareRepositoryTest.php b/src/Bundle/ChillPersonBundle/Tests/Repository/AccompanyingPeriodACLAwareRepositoryTest.php index 032bce7e7..050a839e6 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Repository/AccompanyingPeriodACLAwareRepositoryTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Repository/AccompanyingPeriodACLAwareRepositoryTest.php @@ -52,6 +52,11 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase private static array $periodsIdsToDelete = []; + /** + * @var list> + */ + private static array $entitiesToDelete = []; + protected function setUp(): void { self::bootKernel(); @@ -80,7 +85,14 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase $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"); } - $persons = $this->entityManager - ->createQuery("SELECT p FROM " . Person::class . " p WHERE SIZE(p.accompanyingPeriodParticipations) = 0") - ->setMaxResults(4) - ->getResult(); + if (null === $centerA = $this->entityManager->createQuery("SELECT c FROM " . Center::class . " c WHERE c.name LIKE :cn")->setParameter('cn', 'Center A') + ->setMaxResults(1)->getSingleResult()) { + throw new \RuntimeException("Center A not found"); + } + $persons = [new Person(), new Person(), new Person(), new Person()]; + $firstnames = ['alpha', 'beta', 'gamma', 'delta']; + $lastnames = ['primo', 'secundo', 'tertio', 'quartro']; - if (4 > count($persons)) { - throw new \RuntimeException("no person found"); + foreach ($persons as $k => $p) { + $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;