correct test

This commit is contained in:
Julie Lenaerts 2023-10-04 10:43:37 +02:00
parent b0a7612329
commit af4bee4d50

View File

@ -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];
}
}