mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-31 09:18:24 +00:00 
			
		
		
		
	DX: Fix test for PersonMoveTest.php
This commit is contained in:
		| @@ -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<array{0: class-string, 1: int}> | ||||
|      */ | ||||
| @@ -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"]; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user