From 29983cc2ad1657878a04adf0b1a0538ea82ce430 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 21 Sep 2023 16:18:51 +0200 Subject: [PATCH] Work on test, but still fails --- .../AccompanyingCourseExportHelperTest.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php b/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php index bc7f413d7..a254a0d9c 100644 --- a/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php @@ -20,16 +20,13 @@ class AccompanyingCourseExportHelperTest extends KernelTestCase private EntityManagerInterface $em; - private EntityRepository $repository; - private AccompanyingCourseExportHelper $accompanyingCourseExportHelper; protected function setUp(): void { self::bootKernel(); $this->em = self::$container->get(EntityManagerInterface::class); - $this->repository = self::$container->get($this->em->getRepository(AccompanyingPeriod::class)); - $this->accompanyingPeriodExportHelper = self::$container->get(AccompanyingCourseExportHelper::class); + $this->accompanyingCourseExportHelper = self::$container->get(AccompanyingCourseExportHelper::class); } public static function tearDownAfterClass(): void @@ -57,14 +54,19 @@ class AccompanyingCourseExportHelperTest extends KernelTestCase AccompanyingPeriod $periodC // canceled (child cm of canceled cm) ): void { - $qb = $this->repository->createQueryBuilder('acp'); - $qb->select('acp.id')->from(AccompanyingPeriod::class, 'acp'); + $qb = $this->em->getRepository(AccompanyingPeriod::class)->createQueryBuilder('acp'); $this->accompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $qb->select('acp.id'); + $periodIdsFound = $qb->getQuery()->getResult(); + $periodA = $this->em->find(AccompanyingPeriod::class, $periodA->getId()); + $periodB = $this->em->find(AccompanyingPeriod::class, $periodB->getId()); + $periodC = $this->em->find(AccompanyingPeriod::class, $periodC->getId()); + self::assertContains($periodB->getId(), $periodIdsFound, 'Period without canceled closing motive has been found'); - self::assertNotContains($periodA->getId(), $periodIdsFound, 'Period with canceled closing motive has not been found'); + self::assertNotContains($periodA->getdId(), $periodIdsFound, 'Period with canceled closing motive has not been found'); self::assertNotContains($periodC->getId(), $periodIdsFound, 'Period with child canceled closing motive has not been found'); } @@ -97,15 +99,15 @@ class AccompanyingCourseExportHelperTest extends KernelTestCase $this->em->persist($periodB); $this->em->persist($periodC); + self::$entitiesToDelete[] = [ClosingMotive::class, $cmChild]; self::$entitiesToDelete[] = [ClosingMotive::class, $cmA]; self::$entitiesToDelete[] = [ClosingMotive::class, $cmB]; - self::$entitiesToDelete[] = [ClosingMotive::class, $cmChild]; self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodA]; self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodB]; self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodC]; - yield [$periodA, $periodB, $periodC]; + yield [$periodA, $periodB, $periodC, 'Verify that period with non-canceling closing motive is found']; $this->em->flush(); $this->em->clear();