[test] add dataprovider for testing move person where both are participating in the same parcours

This commit is contained in:
Julie Lenaerts 2023-07-13 16:18:39 +02:00
parent e0cdf06e99
commit 860e076b89
2 changed files with 19 additions and 45 deletions

View File

@ -1,45 +0,0 @@
<?php
namespace Chill\PersonBundle\Actions\Remove\Handler;
use Chill\PersonBundle\Actions\Remove\PersonMoveSqlHandlerInterface;
use Chill\PersonBundle\Entity\Person;
class PersonMoveCenterHistoryHandler implements PersonMoveSqlHandlerInterface
{
public function supports(string $className, string $field): bool
{
return $className === Person\PersonCenterHistory::class;
}
public function getSqls(string $className, string $field, Person $from, Person $to): array
{
$insertSql = sprintf(<<<SQL
INSERT INTO chill_person_person_center_history (id, person_id, center_id, startdate, enddate, createdat, updatedat, createdby_id, updatedby_id)
SELECT nextval('chill_person_person_center_history_id_seq'), %d, center_id, startdate, enddate, createdat, updatedat, createdby_id, updatedby_id
FROM chill_person_person_center_history cppch
WHERE person_id = %d
AND NOT EXISTS (
SELECT 1 FROM chill_person_person_center_history cppch2
WHERE
person_id = %d
AND daterange(cppch.startdate, cppch.enddate) && daterange(cppch2.startdate, cppch2.enddate)
)
SQL, $to->getId(), $from->getId(), $to->getId());
$updateSql = sprintf(<<<SQL
UPDATE chill_person_person_center_history cppch
SET startdate =
WHERE person_id = %d
AND EXISTS (
SELECT 1 FROM chill_person_person_center_history cppch2
WHERE
person_id = %d
AND daterange(cppch.startdate, cppch.enddate) && daterange(cppch2.startdate, cppch2.enddate)
)
SQL, $to->getId());
}
}

View File

@ -5,6 +5,8 @@ namespace Action\Remove;
use Chill\ActivityBundle\Entity\Activity;
use Chill\PersonBundle\Actions\Remove\PersonMove;
use Chill\PersonBundle\Actions\Remove\PersonMoveManager;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Person;
@ -132,6 +134,23 @@ class PersonMoveTest extends KernelTestCase
yield [$personA, $personB, "move 2 people having the same household at the same time"];
$personA = new Person();
$personB = new Person();
$parcours = new AccompanyingPeriod();
$parcours->addPerson($personA);
$parcours->addPerson($personB);
$this->em->persist($personA);
$this->em->persist($personB);
$this->em->persist($parcours);
self::$entitiesToDelete[] = [Person::class, $personA];
self::$entitiesToDelete[] = [Person::class, $personB];
self::$entitiesToDelete[] = [AccompanyingPeriod::class, $parcours];
yield [$personA, $personB, "move 2 people participating to the same parcours"];
$this->em->flush();
$this->em->clear();
}