mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add test for accompanyingPeriodExportHelper: closing motive exclusion
This commit is contained in:
parent
500b37601a
commit
260a173a61
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Export;
|
||||
|
||||
use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
class AccompanyingCourseExportHelperTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var list<array{0: class-string, 1: int}>
|
||||
*/
|
||||
private static array $entitiesToDelete = [];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
foreach (self::$entitiesToDelete as [$class, $id]) {
|
||||
$entity = $em->find($class, $id);
|
||||
|
||||
if (null !== $entity) {
|
||||
$em->remove($entity);
|
||||
}
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderExclusionOnClosingMotive
|
||||
*/
|
||||
public function testExclusionOnClosingMotive(
|
||||
AccompanyingPeriod $periodA, //canceled
|
||||
AccompanyingPeriod $periodB, // not canceled
|
||||
AccompanyingPeriod $periodC // canceled (child cm of canceled cm)
|
||||
): void
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('acp');
|
||||
$qb->select('acp.id')->from(AccompanyingPeriod::class, 'acp');
|
||||
$this->accompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
||||
|
||||
$periodIdsFound = $qb->getQuery()->getResult();
|
||||
|
||||
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($periodC->getId(), $periodIdsFound, 'Period with child canceled closing motive has not been found');
|
||||
}
|
||||
|
||||
public function dataProviderExclusionOnClosingMotive(): iterable
|
||||
{
|
||||
$this->setUp();
|
||||
|
||||
$cmA = new ClosingMotive();
|
||||
$cmA->setIsCanceledAccompanyingPeriod(true);
|
||||
|
||||
$cmB = new ClosingMotive();
|
||||
$cmB->setIsCanceledAccompanyingPeriod(false);
|
||||
|
||||
$cmChild = new ClosingMotive();
|
||||
$cmChild->setParent($cmA);
|
||||
|
||||
$this->em->persist($cmA);
|
||||
$this->em->persist($cmB);
|
||||
$this->em->persist($cmChild);
|
||||
|
||||
$periodA = new AccompanyingPeriod();
|
||||
$periodB = new AccompanyingPeriod();
|
||||
$periodC = new AccompanyingPeriod();
|
||||
|
||||
$periodA->setClosingMotive($cmA);
|
||||
$periodB->setClosingMotive($cmB);
|
||||
$periodC->setClosingMotive($cmChild);
|
||||
|
||||
$this->em->persist($periodA);
|
||||
$this->em->persist($periodB);
|
||||
$this->em->persist($periodC);
|
||||
|
||||
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];
|
||||
|
||||
$this->em->flush();
|
||||
$this->em->clear();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user