From 0df93fb7030138a112d86190d1d58ac61ba9e64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 16 Oct 2023 17:19:28 +0200 Subject: [PATCH] DX: Fix test for PersonMoveTest.php --- .../Tests/Action/Remove/PersonMoveTest.php | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php b/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php index ce3d8a3d1..64826930f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Action/Remove/PersonMoveTest.php @@ -24,6 +24,7 @@ use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Relationships\Relation; use Chill\PersonBundle\Entity\Relationships\Relationship; +use Chill\PersonBundle\Repository\Person\PersonCenterHistoryInterface; use Chill\PersonBundle\Repository\PersonRepository; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; @@ -44,6 +45,8 @@ class PersonMoveTest extends KernelTestCase private CenterRepositoryInterface $centerRepository; + private PersonCenterHistoryInterface $personCenterHistory; + /** * @var list */ @@ -56,6 +59,7 @@ class PersonMoveTest extends KernelTestCase $this->personMoveManager = self::$container->get(PersonMoveManager::class); $this->eventDispatcher = self::$container->get(EventDispatcherInterface::class); $this->centerRepository = self::$container->get(CenterRepositoryInterface::class); + $this->personCenterHistory = self::$container->get(PersonCenterHistoryInterface::class); } public static function tearDownAfterClass(): void @@ -146,18 +150,22 @@ class PersonMoveTest extends KernelTestCase $personB = $this->em->find(Person::class, $personB->getId()); $message = 'Move persons with overlapping center histories'; - $this->em->refresh($personB); - self::assertCount(0, $personsByIdOfA); self::assertNotNull($personB?->getId(), $message); - $centerHistoriesB = $personB->getCenterHistory(); - $oldestDate = new \DateTimeImmutable('2023-01-01'); + $centersHistories = $this->personCenterHistory->findBy(['person' => $personB]); - $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::assertEquals($oldestDate, $centerHistoriesB->first()->getStartDate()); + self::assertCount(2, $centersHistories); + self::assertEquals('2023-01-01', $oldestCenterHistory?->getStartDate()->format('Y-m-d')); self::$entitiesToDelete[] = [Person::class, $personA]; self::$entitiesToDelete[] = [Person::class, $personB]; @@ -218,11 +226,11 @@ class PersonMoveTest extends KernelTestCase $this->em->persist($memberA); $this->em->persist($memberB); - self::$entitiesToDelete[] = [Person::class, $personA]; - self::$entitiesToDelete[] = [Person::class, $personB]; self::$entitiesToDelete[] = [HouseholdMember::class, $memberA]; self::$entitiesToDelete[] = [HouseholdMember::class, $memberB]; 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"];