Merge branch '146_parcours_annules' into rector/rules-symfony

This commit is contained in:
2023-10-16 17:52:06 +02:00
28 changed files with 314 additions and 16 deletions

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Export;
use Doctrine\ORM\QueryBuilder;
final readonly class AccompanyingCourseExportHelper
{
public static function addClosingMotiveExclusionClause(QueryBuilder $qb): QueryBuilder
{
$qb->leftJoin('acp.closingMotive', 'cm')
->andWhere(
$qb->expr()->orX(
$qb->expr()->eq('cm.isCanceledAccompanyingPeriod', 'false'),
$qb->expr()->isNull('acp.closingMotive')
)
);
return $qb;
}
}

View File

@@ -0,0 +1,122 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
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;
/**
* @internal
* @coversNothing
*/
class AccompanyingCourseExportHelperTest extends KernelTestCase
{
/**
* @var list<array{0: class-string, 1: int}>
*/
private static array $entitiesToDelete = [];
private EntityManagerInterface $em;
private AccompanyingCourseExportHelper $accompanyingCourseExportHelper;
protected function setUp(): void
{
self::bootKernel();
$this->em = self::$container->get(EntityManagerInterface::class);
$this->accompanyingCourseExportHelper = 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();
}
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 = 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->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');
}
private function prepareData()
{
$cmA = new ClosingMotive();
$cmA->setIsCanceledAccompanyingPeriod(false);
$cmB = new ClosingMotive();
$cmB->setIsCanceledAccompanyingPeriod(true);
$cmChild = new ClosingMotive();
$cmB->addChildren($cmChild);
$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, $cmChild];
self::$entitiesToDelete[] = [ClosingMotive::class, $cmA];
self::$entitiesToDelete[] = [ClosingMotive::class, $cmB];
self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodA];
self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodB];
self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodC];
$this->em->flush();
$this->em->clear();
return [$periodA, $periodB, $periodC];
}
}

View File

@@ -52,3 +52,5 @@ services:
$exportManager: '@Chill\MainBundle\Export\ExportManager'
tags:
- { name: chill.export_formatter, alias: 'csv_pivoted_list' }
Chill\MainBundle\Export\AccompanyingCourseExportHelper: ~