DX: Fix test for PersonMoveTest.php

This commit is contained in:
Julien Fastré 2023-10-16 17:19:28 +02:00
parent c62495a280
commit 0df93fb703
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -24,6 +24,7 @@ use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Relationships\Relation; use Chill\PersonBundle\Entity\Relationships\Relation;
use Chill\PersonBundle\Entity\Relationships\Relationship; use Chill\PersonBundle\Entity\Relationships\Relationship;
use Chill\PersonBundle\Repository\Person\PersonCenterHistoryInterface;
use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Repository\PersonRepository;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -44,6 +45,8 @@ class PersonMoveTest extends KernelTestCase
private CenterRepositoryInterface $centerRepository; private CenterRepositoryInterface $centerRepository;
private PersonCenterHistoryInterface $personCenterHistory;
/** /**
* @var list<array{0: class-string, 1: int}> * @var list<array{0: class-string, 1: int}>
*/ */
@ -56,6 +59,7 @@ class PersonMoveTest extends KernelTestCase
$this->personMoveManager = self::$container->get(PersonMoveManager::class); $this->personMoveManager = self::$container->get(PersonMoveManager::class);
$this->eventDispatcher = self::$container->get(EventDispatcherInterface::class); $this->eventDispatcher = self::$container->get(EventDispatcherInterface::class);
$this->centerRepository = self::$container->get(CenterRepositoryInterface::class); $this->centerRepository = self::$container->get(CenterRepositoryInterface::class);
$this->personCenterHistory = self::$container->get(PersonCenterHistoryInterface::class);
} }
public static function tearDownAfterClass(): void public static function tearDownAfterClass(): void
@ -146,18 +150,22 @@ class PersonMoveTest extends KernelTestCase
$personB = $this->em->find(Person::class, $personB->getId()); $personB = $this->em->find(Person::class, $personB->getId());
$message = 'Move persons with overlapping center histories'; $message = 'Move persons with overlapping center histories';
$this->em->refresh($personB);
self::assertCount(0, $personsByIdOfA); self::assertCount(0, $personsByIdOfA);
self::assertNotNull($personB?->getId(), $message); self::assertNotNull($personB?->getId(), $message);
$centerHistoriesB = $personB->getCenterHistory(); $centersHistories = $this->personCenterHistory->findBy(['person' => $personB]);
$oldestDate = new \DateTimeImmutable('2023-01-01');
$this->em->refresh($centerHistoriesB->first()); // compute the oldest center history
$oldestCenterHistory = null;
foreach ($centersHistories as $centerHistory) {
$this->em->refresh($centerHistory);
if (null === $oldestCenterHistory || ($oldestCenterHistory instanceof Person\PersonCenterHistory && $oldestCenterHistory->getStartDate() >= $centerHistory->getStartDate())) {
$oldestCenterHistory = $centerHistory;
}
}
self::assertCount(2, $centerHistoriesB); self::assertCount(2, $centersHistories);
self::assertEquals($oldestDate, $centerHistoriesB->first()->getStartDate()); self::assertEquals('2023-01-01', $oldestCenterHistory?->getStartDate()->format('Y-m-d'));
self::$entitiesToDelete[] = [Person::class, $personA]; self::$entitiesToDelete[] = [Person::class, $personA];
self::$entitiesToDelete[] = [Person::class, $personB]; self::$entitiesToDelete[] = [Person::class, $personB];
@ -218,11 +226,11 @@ class PersonMoveTest extends KernelTestCase
$this->em->persist($memberA); $this->em->persist($memberA);
$this->em->persist($memberB); $this->em->persist($memberB);
self::$entitiesToDelete[] = [Person::class, $personA];
self::$entitiesToDelete[] = [Person::class, $personB];
self::$entitiesToDelete[] = [HouseholdMember::class, $memberA]; self::$entitiesToDelete[] = [HouseholdMember::class, $memberA];
self::$entitiesToDelete[] = [HouseholdMember::class, $memberB]; self::$entitiesToDelete[] = [HouseholdMember::class, $memberB];
self::$entitiesToDelete[] = [Household::class, $household]; self::$entitiesToDelete[] = [Household::class, $household];
self::$entitiesToDelete[] = [Person::class, $personA];
self::$entitiesToDelete[] = [Person::class, $personB];
yield [$personA, $personB, "move 2 people having the same household at the same time"]; yield [$personA, $personB, "move 2 people having the same household at the same time"];