From af4bee4d509a695b1be2a60516a2f5c4de27f422 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 4 Oct 2023 10:43:37 +0200 Subject: [PATCH] correct test --- .../AccompanyingCourseExportHelperTest.php | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php b/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php index 1e10e4834..908c17f3f 100644 --- a/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php @@ -58,34 +58,27 @@ class AccompanyingCourseExportHelperTest extends KernelTestCase $em->flush(); } - /** - * @dataProvider dataProviderExclusionOnClosingMotive - */ - public function testExclusionOnClosingMotive( - AccompanyingPeriod $periodA, //not canceled - AccompanyingPeriod $periodB, // canceled - AccompanyingPeriod $periodC // canceled (child cm of canceled cm) - ): void { + public function testExclusionOnClosingMotive(): void { + [$periodA, $periodB, $periodC] = $this->prepareData(); + $qb = $this->em->getRepository(AccompanyingPeriod::class)->createQueryBuilder('acp'); $this->accompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); $qb->select('acp.id'); - $periodIdsFound = $qb->getQuery()->getResult(); + $periodIdsFound = array_map(fn ($el) => $el['id'], $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($periodA->getId(), $periodIdsFound, 'Period without canceled closing motive has been found'); - self::assertNotContains($periodB->getdId(), $periodIdsFound, 'Period with canceled closing motive has not been found'); + self::assertNotContains($periodB->getId(), $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'); } - public function dataProviderExclusionOnClosingMotive(): iterable + private function prepareData() { - $this->setUp(); - $cmA = new ClosingMotive(); $cmA->setIsCanceledAccompanyingPeriod(false); @@ -93,7 +86,7 @@ class AccompanyingCourseExportHelperTest extends KernelTestCase $cmB->setIsCanceledAccompanyingPeriod(true); $cmChild = new ClosingMotive(); - $cmChild->setParent($cmB); + $cmB->addChildren($cmChild); $this->em->persist($cmA); $this->em->persist($cmB); @@ -119,10 +112,10 @@ class AccompanyingCourseExportHelperTest extends KernelTestCase self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodB]; self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodC]; - yield [$periodA, $periodB, $periodC, 'Verify that period with non-canceling closing motive is found']; - $this->em->flush(); $this->em->clear(); + + return [$periodA, $periodB, $periodC]; } }