This commit is contained in:
2025-06-20 17:31:13 +02:00
parent 9158e33854
commit a38116cca4
65 changed files with 2298 additions and 2298 deletions

View File

@@ -99,81 +99,6 @@ class PersonMoveTest extends KernelTestCase
self::assertNotNull($personB?->getId(), $message);
}
public function testMovePersonCenterHistory(): void
{
$personA = new Person();
$personB = new Person();
[$centerA, $centerB] = $this->centerRepository->findAll();
$this->em->persist($personA);
$this->em->persist($personB);
$personCenterHistoryAFirst = (new Person\PersonCenterHistory())->setCenter($centerA)
->setStartDate(new \DateTimeImmutable('2023-01-01'))
->setEndDate(new \DateTimeImmutable('2023-06-30'));
$personCenterHistoryASecond = (new Person\PersonCenterHistory())->setCenter($centerB)
->setStartDate(new \DateTimeImmutable('2023-06-30'))
->setEndDate(new \DateTimeImmutable('2023-09-30'));
$personCenterHistoryBFirst = (new Person\PersonCenterHistory())->setCenter($centerA)
->setStartDate(new \DateTimeImmutable('2023-03-01'))
->setEndDate(new \DateTimeImmutable('2023-07-15'));
$personCenterHistoryBSecond = (new Person\PersonCenterHistory())->setCenter($centerB)
->setStartDate(new \DateTimeImmutable('2023-07-15'))
->setEndDate(new \DateTimeImmutable('2023-09-30'));
$this->em->persist($personCenterHistoryAFirst);
$this->em->persist($personCenterHistoryASecond);
$this->em->persist($personCenterHistoryBFirst);
$this->em->persist($personCenterHistoryBSecond);
$personA->addCenterHistory($personCenterHistoryAFirst);
$personA->addCenterHistory($personCenterHistoryASecond);
$personB->addCenterHistory($personCenterHistoryBFirst);
$personB->addCenterHistory($personCenterHistoryBSecond);
$this->em->flush();
$this->em->clear();
$move = new PersonMove($this->em, $this->personMoveManager, $this->eventDispatcher);
$sqls = $move->getSQL($personA, $personB);
$this->em->getConnection()->transactional(function (Connection $conn) use ($sqls) {
foreach ($sqls as $sql) {
$conn->executeStatement($sql);
}
});
$personsByIdOfA = $this->em->createQuery('SELECT p FROM '.Person::class.' p WHERE p.id = :id')
->setParameter('id', $personA->getId())
->getResult();
/** @var Person $personB */
$personB = $this->em->find(Person::class, $personB->getId());
$message = 'Move persons with overlapping center histories';
self::assertCount(0, $personsByIdOfA);
self::assertNotNull($personB?->getId(), $message);
$centersHistories = $this->personCenterHistory->findBy(['person' => $personB]);
// 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, $centersHistories);
self::assertEquals('2023-01-01', $oldestCenterHistory?->getStartDate()->format('Y-m-d'));
self::$entitiesToDelete[] = [Person::class, $personA];
self::$entitiesToDelete[] = [Person::class, $personB];
self::$entitiesToDelete[] = [Person\PersonCenterHistory::class, $personCenterHistoryAFirst];
self::$entitiesToDelete[] = [Person\PersonCenterHistory::class, $personCenterHistoryASecond];
self::$entitiesToDelete[] = [Person\PersonCenterHistory::class, $personCenterHistoryBFirst];
self::$entitiesToDelete[] = [Person\PersonCenterHistory::class, $personCenterHistoryBSecond];
}
public static function dataProviderMovePerson(): iterable
{
self::bootKernel();
@@ -280,4 +205,79 @@ class PersonMoveTest extends KernelTestCase
$em->flush();
$em->clear();
}
public function testMovePersonCenterHistory(): void
{
$personA = new Person();
$personB = new Person();
[$centerA, $centerB] = $this->centerRepository->findAll();
$this->em->persist($personA);
$this->em->persist($personB);
$personCenterHistoryAFirst = (new Person\PersonCenterHistory())->setCenter($centerA)
->setStartDate(new \DateTimeImmutable('2023-01-01'))
->setEndDate(new \DateTimeImmutable('2023-06-30'));
$personCenterHistoryASecond = (new Person\PersonCenterHistory())->setCenter($centerB)
->setStartDate(new \DateTimeImmutable('2023-06-30'))
->setEndDate(new \DateTimeImmutable('2023-09-30'));
$personCenterHistoryBFirst = (new Person\PersonCenterHistory())->setCenter($centerA)
->setStartDate(new \DateTimeImmutable('2023-03-01'))
->setEndDate(new \DateTimeImmutable('2023-07-15'));
$personCenterHistoryBSecond = (new Person\PersonCenterHistory())->setCenter($centerB)
->setStartDate(new \DateTimeImmutable('2023-07-15'))
->setEndDate(new \DateTimeImmutable('2023-09-30'));
$this->em->persist($personCenterHistoryAFirst);
$this->em->persist($personCenterHistoryASecond);
$this->em->persist($personCenterHistoryBFirst);
$this->em->persist($personCenterHistoryBSecond);
$personA->addCenterHistory($personCenterHistoryAFirst);
$personA->addCenterHistory($personCenterHistoryASecond);
$personB->addCenterHistory($personCenterHistoryBFirst);
$personB->addCenterHistory($personCenterHistoryBSecond);
$this->em->flush();
$this->em->clear();
$move = new PersonMove($this->em, $this->personMoveManager, $this->eventDispatcher);
$sqls = $move->getSQL($personA, $personB);
$this->em->getConnection()->transactional(function (Connection $conn) use ($sqls) {
foreach ($sqls as $sql) {
$conn->executeStatement($sql);
}
});
$personsByIdOfA = $this->em->createQuery('SELECT p FROM '.Person::class.' p WHERE p.id = :id')
->setParameter('id', $personA->getId())
->getResult();
/** @var Person $personB */
$personB = $this->em->find(Person::class, $personB->getId());
$message = 'Move persons with overlapping center histories';
self::assertCount(0, $personsByIdOfA);
self::assertNotNull($personB?->getId(), $message);
$centersHistories = $this->personCenterHistory->findBy(['person' => $personB]);
// 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, $centersHistories);
self::assertEquals('2023-01-01', $oldestCenterHistory?->getStartDate()->format('Y-m-d'));
self::$entitiesToDelete[] = [Person::class, $personA];
self::$entitiesToDelete[] = [Person::class, $personB];
self::$entitiesToDelete[] = [Person\PersonCenterHistory::class, $personCenterHistoryAFirst];
self::$entitiesToDelete[] = [Person\PersonCenterHistory::class, $personCenterHistoryASecond];
self::$entitiesToDelete[] = [Person\PersonCenterHistory::class, $personCenterHistoryBFirst];
self::$entitiesToDelete[] = [Person\PersonCenterHistory::class, $personCenterHistoryBSecond];
}
}

View File

@@ -48,251 +48,6 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public static function dataGenerateNewAccompanyingCourse()
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$period = new AccompanyingPeriod(new \DateTime('1 week ago'));
$user = $em->getRepository(User::class)
->findOneByUsernameCanonical('center a_social');
$period->setCreatedBy($user);
// $period->setCreatedAt(new \DateTime('yesterday'));
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$personIds = $em->createQuery('SELECT p.id FROM '.
Person::class.' p JOIN p.centerCurrent cc'.
' WHERE cc.center = :center')
->setParameter('center', $center)
->setMaxResults(100)
->getScalarResult();
// create a random order
shuffle($personIds);
for ($i = 0; 2 > $i; ++$i) {
$person = $em->getRepository(Person::class)->find(\array_pop($personIds));
$period->addPerson($person);
}
$em->persist($period);
$em->flush();
yield [$period];
self::ensureKernelShutdown();
}
public static function dataGenerateRandomAccompanyingCourse()
{
// note about max result for person query, and maxGenerated:
//
// in the final loop, an id is popped out of the personIds array twice:
//
// * one for getting the person, which will in turn provide his accompanying period;
// * one for getting the personId to populate to the data manager
//
// Ensure to keep always $maxGenerated to the double of $maxResults. x8 is a good compromize :)
$maxGenerated = 3;
$maxResults = $maxGenerated * 8;
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$qb = $em->createQueryBuilder();
$personIds = $qb
->select('p.id')
->distinct(true)
->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'participation')
->join('participation.accompanyingPeriod', 'ap')
->join('p.centerCurrent', 'cc')
->where(
$qb->expr()->eq(
'cc.center',
':center'
)
)
->andWhere(
$qb->expr()->gt(
'SIZE(p.accompanyingPeriodParticipations)',
0
)
)
->andWhere(
$qb->expr()->eq('ap.step', ':step')
)
->setParameter('center', $center)
->setParameter('step', AccompanyingPeriod::STEP_CONFIRMED)
->setMaxResults($maxResults)
->getQuery()
->getScalarResult();
// create a random order
shuffle($personIds);
$nbGenerated = 0;
while ($nbGenerated < $maxGenerated) {
$id = \array_pop($personIds)['id'];
$person = $em->getRepository(Person::class)
->find($id);
$periods = $person->getAccompanyingPeriods();
yield [\array_pop($personIds)['id'], $periods[\array_rand($periods)]->getId()];
++$nbGenerated;
}
self::ensureKernelShutdown();
}
public static function dataGenerateRandomAccompanyingCourseWithSocialIssue()
{
// note about max result for person query, and maxGenerated:
//
// in the final loop, an id is popped out of the personIds array twice:
//
// * one for getting the person, which will in turn provide his accompanying period;
// * one for getting the personId to populate to the data manager
//
// Ensure to keep always $maxGenerated to the double of $maxResults. x8 is a good compromize :)
$maxGenerated = 3;
$maxResults = $maxGenerated * 8;
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$qb = $em->createQueryBuilder();
$personIds = $qb
->select('p.id')
->distinct(true)
->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'participation')
->join('participation.accompanyingPeriod', 'ap')
->join('p.centerCurrent', 'cc')
->where(
$qb->expr()->eq(
'cc.center',
':center'
)
)
->andWhere(
$qb->expr()->gt(
'SIZE(p.accompanyingPeriodParticipations)',
0
)
)
->andWhere(
$qb->expr()->eq('ap.step', ':step')
)
->setParameter('center', $center)
->setParameter('step', AccompanyingPeriod::STEP_CONFIRMED)
->setMaxResults($maxResults)
->getQuery()
->getScalarResult();
// create a random order
shuffle($personIds);
$socialIssues = $em->createQuery('SELECT s FROM '.
SocialIssue::class.' s ')
->setMaxResults(10)
->getResult();
$nbGenerated = 0;
while ($nbGenerated < $maxGenerated) {
$id = \array_pop($personIds)['id'];
$person = $em->getRepository(Person::class)
->find($id);
$periods = $person->getAccompanyingPeriods();
yield [$periods[\array_rand($periods)], $socialIssues[\array_rand($socialIssues)]];
++$nbGenerated;
}
self::ensureKernelShutdown();
}
public static function dataGenerateRandomRequestorValidData(): \Iterator
{
$dataLength = 2;
$maxResults = 100;
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$qb = $em->createQueryBuilder();
$personIds = $qb
->select('p.id')
->distinct(true)
->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'participation')
->join('participation.accompanyingPeriod', 'ap')
->join('p.centerCurrent', 'cc')
->where(
$qb->expr()->eq(
'cc.center',
':center'
)
)
->andWhere(
$qb->expr()->gt(
'SIZE(p.accompanyingPeriodParticipations)',
0
)
)
->andWhere(
$qb->expr()->eq('ap.step', ':step')
)
->setParameter('center', $center)
->setParameter('step', AccompanyingPeriod::STEP_CONFIRMED)
->setMaxResults($maxResults)
->getQuery()
->getScalarResult();
// create a random order
shuffle($personIds);
$thirdPartyIds = $em->createQuery('SELECT t.id FROM '.
ThirdParty::class.' t ')
->setMaxResults($maxResults)
->getScalarResult();
// create a random order
shuffle($thirdPartyIds);
$i = 0;
while ($i <= $dataLength) {
$person = $em->getRepository(Person::class)
->find(\array_pop($personIds)['id']);
if (0 === \count($person->getAccompanyingPeriods())) {
continue;
}
$period = $person->getAccompanyingPeriods()[0];
yield [$period, \array_pop($personIds)['id'], \array_pop($thirdPartyIds)['id']];
++$i;
}
self::ensureKernelShutdown();
}
/**
* @dataProvider dataGenerateRandomAccompanyingCourse
*/
@@ -403,6 +158,78 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
$this->assertTrue(\in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
}
public static function dataGenerateRandomAccompanyingCourseWithSocialIssue()
{
// note about max result for person query, and maxGenerated:
//
// in the final loop, an id is popped out of the personIds array twice:
//
// * one for getting the person, which will in turn provide his accompanying period;
// * one for getting the personId to populate to the data manager
//
// Ensure to keep always $maxGenerated to the double of $maxResults. x8 is a good compromize :)
$maxGenerated = 3;
$maxResults = $maxGenerated * 8;
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$qb = $em->createQueryBuilder();
$personIds = $qb
->select('p.id')
->distinct(true)
->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'participation')
->join('participation.accompanyingPeriod', 'ap')
->join('p.centerCurrent', 'cc')
->where(
$qb->expr()->eq(
'cc.center',
':center'
)
)
->andWhere(
$qb->expr()->gt(
'SIZE(p.accompanyingPeriodParticipations)',
0
)
)
->andWhere(
$qb->expr()->eq('ap.step', ':step')
)
->setParameter('center', $center)
->setParameter('step', AccompanyingPeriod::STEP_CONFIRMED)
->setMaxResults($maxResults)
->getQuery()
->getScalarResult();
// create a random order
shuffle($personIds);
$socialIssues = $em->createQuery('SELECT s FROM '.
SocialIssue::class.' s ')
->setMaxResults(10)
->getResult();
$nbGenerated = 0;
while ($nbGenerated < $maxGenerated) {
$id = \array_pop($personIds)['id'];
$person = $em->getRepository(Person::class)
->find($id);
$periods = $person->getAccompanyingPeriods();
yield [$periods[\array_rand($periods)], $socialIssues[\array_rand($socialIssues)]];
++$nbGenerated;
}
self::ensureKernelShutdown();
}
/**
* @dataProvider dataGenerateRandomAccompanyingCourse
*/
@@ -525,6 +352,43 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
$this->period = $period;
}
public static function dataGenerateNewAccompanyingCourse()
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$period = new AccompanyingPeriod(new \DateTime('1 week ago'));
$user = $em->getRepository(User::class)
->findOneByUsernameCanonical('center a_social');
$period->setCreatedBy($user);
// $period->setCreatedAt(new \DateTime('yesterday'));
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$personIds = $em->createQuery('SELECT p.id FROM '.
Person::class.' p JOIN p.centerCurrent cc'.
' WHERE cc.center = :center')
->setParameter('center', $center)
->setMaxResults(100)
->getScalarResult();
// create a random order
shuffle($personIds);
for ($i = 0; 2 > $i; ++$i) {
$person = $em->getRepository(Person::class)->find(\array_pop($personIds));
$period->addPerson($person);
}
$em->persist($period);
$em->flush();
yield [$period];
self::ensureKernelShutdown();
}
/**
* @dataProvider dataGenerateRandomAccompanyingCourse
*/
@@ -539,6 +403,73 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
$this->assertTrue(\in_array($client->getResponse()->getStatusCode(), [200, 422], true));
}
public static function dataGenerateRandomAccompanyingCourse()
{
// note about max result for person query, and maxGenerated:
//
// in the final loop, an id is popped out of the personIds array twice:
//
// * one for getting the person, which will in turn provide his accompanying period;
// * one for getting the personId to populate to the data manager
//
// Ensure to keep always $maxGenerated to the double of $maxResults. x8 is a good compromize :)
$maxGenerated = 3;
$maxResults = $maxGenerated * 8;
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$qb = $em->createQueryBuilder();
$personIds = $qb
->select('p.id')
->distinct(true)
->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'participation')
->join('participation.accompanyingPeriod', 'ap')
->join('p.centerCurrent', 'cc')
->where(
$qb->expr()->eq(
'cc.center',
':center'
)
)
->andWhere(
$qb->expr()->gt(
'SIZE(p.accompanyingPeriodParticipations)',
0
)
)
->andWhere(
$qb->expr()->eq('ap.step', ':step')
)
->setParameter('center', $center)
->setParameter('step', AccompanyingPeriod::STEP_CONFIRMED)
->setMaxResults($maxResults)
->getQuery()
->getScalarResult();
// create a random order
shuffle($personIds);
$nbGenerated = 0;
while ($nbGenerated < $maxGenerated) {
$id = \array_pop($personIds)['id'];
$person = $em->getRepository(Person::class)
->find($id);
$periods = $person->getAccompanyingPeriods();
yield [\array_pop($personIds)['id'], $periods[\array_rand($periods)]->getId()];
++$nbGenerated;
}
self::ensureKernelShutdown();
}
/**
* @dataProvider dataGenerateRandomRequestorValidData
*/
@@ -713,6 +644,75 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
}
public static function dataGenerateRandomRequestorValidData(): \Iterator
{
$dataLength = 2;
$maxResults = 100;
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$qb = $em->createQueryBuilder();
$personIds = $qb
->select('p.id')
->distinct(true)
->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'participation')
->join('participation.accompanyingPeriod', 'ap')
->join('p.centerCurrent', 'cc')
->where(
$qb->expr()->eq(
'cc.center',
':center'
)
)
->andWhere(
$qb->expr()->gt(
'SIZE(p.accompanyingPeriodParticipations)',
0
)
)
->andWhere(
$qb->expr()->eq('ap.step', ':step')
)
->setParameter('center', $center)
->setParameter('step', AccompanyingPeriod::STEP_CONFIRMED)
->setMaxResults($maxResults)
->getQuery()
->getScalarResult();
// create a random order
shuffle($personIds);
$thirdPartyIds = $em->createQuery('SELECT t.id FROM '.
ThirdParty::class.' t ')
->setMaxResults($maxResults)
->getScalarResult();
// create a random order
shuffle($thirdPartyIds);
$i = 0;
while ($i <= $dataLength) {
$person = $em->getRepository(Person::class)
->find(\array_pop($personIds)['id']);
if (0 === \count($person->getAccompanyingPeriods())) {
continue;
}
$period = $person->getAccompanyingPeriods()[0];
yield [$period, \array_pop($personIds)['id'], \array_pop($thirdPartyIds)['id']];
++$i;
}
self::ensureKernelShutdown();
}
public function testShow404()
{
$client = $this->getClientAuthenticated();

View File

@@ -41,32 +41,6 @@ final class AccompanyingCourseControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public static function dataGenerateRandomUsers(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$period = new AccompanyingPeriod(new \DateTime('1 week ago'));
$user = $em->getRepository(User::class)
->findOneByUsernameCanonical('center a_social');
$period->setCreatedBy($user);
// $period->setCreatedAt(new \DateTime('yesterday'));
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$personIds = $em->createQuery('SELECT p.id FROM '.
Person::class.' p JOIN p.centerCurrent cc '.
' WHERE cc.center = :center')
->setParameter('center', $center)
->setMaxResults(100)
->getScalarResult();
yield [\array_pop($personIds), \array_pop($personIds)];
self::ensureKernelShutdown();
}
public function testNewWithoutUsers()
{
$this->client->request('GET', '/fr/person/parcours/new');
@@ -104,4 +78,30 @@ final class AccompanyingCourseControllerTest extends WebTestCase
$this->assertEquals(2, \count($period->getParticipations()));
}
public static function dataGenerateRandomUsers(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$period = new AccompanyingPeriod(new \DateTime('1 week ago'));
$user = $em->getRepository(User::class)
->findOneByUsernameCanonical('center a_social');
$period->setCreatedBy($user);
// $period->setCreatedAt(new \DateTime('yesterday'));
$center = $em->getRepository(Center::class)
->findOneBy(['name' => 'Center A']);
$personIds = $em->createQuery('SELECT p.id FROM '.
Person::class.' p JOIN p.centerCurrent cc '.
' WHERE cc.center = :center')
->setParameter('center', $center)
->setMaxResults(100)
->getScalarResult();
yield [\array_pop($personIds), \array_pop($personIds)];
self::ensureKernelShutdown();
}
}

View File

@@ -37,6 +37,28 @@ final class HouseholdApiControllerTest extends WebTestCase
private static array $toDelete = [];
/**
* @dataProvider generateHouseholdAssociatedWithAddressReference
*/
public function testFindHouseholdByAddressReference(int $addressReferenceId, int $expectedHouseholdId)
{
$client = $this->getClientAuthenticated();
$client->request(
Request::METHOD_GET,
"/api/1.0/person/household/by-address-reference/{$addressReferenceId}.json"
);
$this->assertResponseIsSuccessful();
$data = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
$this->assertArrayHasKey('count', $data);
$this->assertArrayHasKey('results', $data);
$householdIds = \array_map(static fn ($r) => $r['id'], $data['results']);
$this->assertContains($expectedHouseholdId, $householdIds);
}
public static function generateHouseholdAssociatedWithAddressReference()
{
self::bootKernel();
@@ -86,6 +108,21 @@ final class HouseholdApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
/**
* @dataProvider generateHouseholdId
*/
public function testSuggestAddressByHousehold(int $householdId)
{
$client = $this->getClientAuthenticated();
$client->request(
Request::METHOD_GET,
"/api/1.0/person/address/suggest/by-household/{$householdId}.json"
);
$this->assertResponseIsSuccessful();
}
public static function generateHouseholdId()
{
self::bootKernel();
@@ -118,6 +155,21 @@ final class HouseholdApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
/**
* @dataProvider generatePersonId
*/
public function testSuggestByAccompanyingPeriodParticipation(int $personId)
{
$client = $this->getClientAuthenticated();
$client->request(
Request::METHOD_GET,
"/api/1.0/person/household/suggest/by-person/{$personId}/through-accompanying-period-participation.json"
);
$this->assertResponseIsSuccessful();
}
public static function generatePersonId()
{
self::bootKernel();
@@ -139,56 +191,4 @@ final class HouseholdApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
/**
* @dataProvider generateHouseholdAssociatedWithAddressReference
*/
public function testFindHouseholdByAddressReference(int $addressReferenceId, int $expectedHouseholdId)
{
$client = $this->getClientAuthenticated();
$client->request(
Request::METHOD_GET,
"/api/1.0/person/household/by-address-reference/{$addressReferenceId}.json"
);
$this->assertResponseIsSuccessful();
$data = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
$this->assertArrayHasKey('count', $data);
$this->assertArrayHasKey('results', $data);
$householdIds = \array_map(static fn ($r) => $r['id'], $data['results']);
$this->assertContains($expectedHouseholdId, $householdIds);
}
/**
* @dataProvider generateHouseholdId
*/
public function testSuggestAddressByHousehold(int $householdId)
{
$client = $this->getClientAuthenticated();
$client->request(
Request::METHOD_GET,
"/api/1.0/person/address/suggest/by-household/{$householdId}.json"
);
$this->assertResponseIsSuccessful();
}
/**
* @dataProvider generatePersonId
*/
public function testSuggestByAccompanyingPeriodParticipation(int $personId)
{
$client = $this->getClientAuthenticated();
$client->request(
Request::METHOD_GET,
"/api/1.0/person/household/suggest/by-person/{$personId}/through-accompanying-period-participation.json"
);
$this->assertResponseIsSuccessful();
}
}

View File

@@ -39,33 +39,6 @@ final class HouseholdControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public static function generateValidHouseholdIds()
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$ids = $em->createQuery(
sprintf('SELECT DISTINCT h.id FROM %s h JOIN h.members m JOIN m.person p JOIN p.centerHistory ch JOIN ch.center c WHERE c.name = :center AND ch.endDate IS NULL', Household::class)
)
->setParameter('center', 'Center A')
->setMaxResults(100)
->getScalarResult();
if ([] === $ids) {
throw new \RuntimeException('no household ids with center "Center A"');
}
\shuffle($ids);
yield [\array_pop($ids)['id']];
yield [\array_pop($ids)['id']];
yield [\array_pop($ids)['id']];
self::ensureKernelShutdown();
}
/**
* @dataProvider generateValidHouseholdIds
*/
@@ -136,4 +109,31 @@ final class HouseholdControllerTest extends WebTestCase
$this->assertResponseIsSuccessful();
}
public static function generateValidHouseholdIds()
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$ids = $em->createQuery(
sprintf('SELECT DISTINCT h.id FROM %s h JOIN h.members m JOIN m.person p JOIN p.centerHistory ch JOIN ch.center c WHERE c.name = :center AND ch.endDate IS NULL', Household::class)
)
->setParameter('center', 'Center A')
->setMaxResults(100)
->getScalarResult();
if ([] === $ids) {
throw new \RuntimeException('no household ids with center "Center A"');
}
\shuffle($ids);
yield [\array_pop($ids)['id']];
yield [\array_pop($ids)['id']];
yield [\array_pop($ids)['id']];
self::ensureKernelShutdown();
}
}

View File

@@ -30,78 +30,6 @@ final class HouseholdMemberControllerTest extends WebTestCase
{
use PrepareClientTrait;
public static function provideValidDataEditMember(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$membershipIds = $em->createQuery(sprintf('SELECT m.id FROM %s m JOIN m.person p JOIN p.centerHistory ch JOIN ch.center c WHERE c.name = :center AND m.endDate IS NULL AND ch.endDate IS NULL', HouseholdMember::class))
->setParameter('center', 'Center A')
->getScalarResult();
if ([] === $membershipIds) {
throw new \RuntimeException("no memberships for person associated to 'Center A'");
}
\shuffle($membershipIds);
yield [\array_pop($membershipIds)['id']];
}
public static function provideValidDataMove(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$yesterday = new \DateTimeImmutable('yesterday');
$personIds = $em->createQuery(
sprintf('SELECT p.id FROM %s p JOIN p.centerHistory ch JOIN ch.center c WHERE c.name = :center AND ch.endDate IS NULL', Person::class)
)
->setParameter('center', 'Center A')
->setMaxResults(100)
->getScalarResult();
if ([] === $personIds) {
throw new \RuntimeException('no person associated with "Center A"');
}
\shuffle($personIds);
$household = new Household();
$em->persist($household);
$em->flush();
$positions = $em->createQuery('SELECT pos.id FROM '.Position::class.' pos '.
'WHERE pos.shareHouseHold = TRUE')
->getResult();
$i = 0;
do {
$id = \array_pop($personIds)['id'];
$person = self::getContainer()->get(EntityManagerInterface::class)
->getRepository(Person::class)
->find($id);
$participation = $person->getCurrentHouseholdParticipationShareHousehold();
if (null === $participation
|| (
null === $participation->getEndDate()
&& $participation->getStartDate() <= $yesterday
)) {
++$i;
yield [
$id,
$household->getId(),
$positions[\random_int(0, \count($positions) - 1)]['id'],
new \DateTimeImmutable('tomorrow'),
];
}
} while (1 >= $i);
}
/**
* @dataProvider provideValidDataEditMember
*/
@@ -124,6 +52,24 @@ final class HouseholdMemberControllerTest extends WebTestCase
$this->assertEquals(302, $client->getResponse()->getStatusCode());
}
public static function provideValidDataEditMember(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$membershipIds = $em->createQuery(sprintf('SELECT m.id FROM %s m JOIN m.person p JOIN p.centerHistory ch JOIN ch.center c WHERE c.name = :center AND m.endDate IS NULL AND ch.endDate IS NULL', HouseholdMember::class))
->setParameter('center', 'Center A')
->getScalarResult();
if ([] === $membershipIds) {
throw new \RuntimeException("no memberships for person associated to 'Center A'");
}
\shuffle($membershipIds);
yield [\array_pop($membershipIds)['id']];
}
/**
* @dataProvider provideValidDataMove
*/
@@ -278,4 +224,58 @@ final class HouseholdMemberControllerTest extends WebTestCase
$this->assertArrayHasKey('id', $data['members'][0]['person']);
$this->assertEquals($personId, $data['members'][0]['person']['id']);
}
public static function provideValidDataMove(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$yesterday = new \DateTimeImmutable('yesterday');
$personIds = $em->createQuery(
sprintf('SELECT p.id FROM %s p JOIN p.centerHistory ch JOIN ch.center c WHERE c.name = :center AND ch.endDate IS NULL', Person::class)
)
->setParameter('center', 'Center A')
->setMaxResults(100)
->getScalarResult();
if ([] === $personIds) {
throw new \RuntimeException('no person associated with "Center A"');
}
\shuffle($personIds);
$household = new Household();
$em->persist($household);
$em->flush();
$positions = $em->createQuery('SELECT pos.id FROM '.Position::class.' pos '.
'WHERE pos.shareHouseHold = TRUE')
->getResult();
$i = 0;
do {
$id = \array_pop($personIds)['id'];
$person = self::getContainer()->get(EntityManagerInterface::class)
->getRepository(Person::class)
->find($id);
$participation = $person->getCurrentHouseholdParticipationShareHousehold();
if (null === $participation
|| (
null === $participation->getEndDate()
&& $participation->getStartDate() <= $yesterday
)) {
++$i;
yield [
$id,
$household->getId(),
$positions[\random_int(0, \count($positions) - 1)]['id'],
new \DateTimeImmutable('tomorrow'),
];
}
} while (1 >= $i);
}
}

View File

@@ -26,47 +26,6 @@ final class PersonApiControllerTest extends WebTestCase
{
use PrepareClientTrait;
public static function dataGetPersonFromCenterA(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$personIds = $em->createQuery(sprintf(
'SELECT p.id FROM %s p JOIN p.centerCurrent pc JOIN pc.center c WHERE c.name = :center',
Person::class
))
->setParameter('center', 'Center A')
->setMaxResults(100)
->getScalarResult();
\shuffle($personIds);
yield \array_pop($personIds);
yield \array_pop($personIds);
yield \array_pop($personIds);
yield \array_pop($personIds);
}
public static function dataGetPersonFromCenterB(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$personIds = $em->createQuery(
sprintf('SELECT p.id FROM %s p JOIN p.centerCurrent pc JOIN pc.center c WHERE c.name = :center', Person::class)
)
->setParameter('center', 'Center B')
->setMaxResults(100)
->getScalarResult();
\shuffle($personIds);
yield \array_pop($personIds);
yield \array_pop($personIds);
}
/**
* @dataProvider dataGetPersonFromCenterA
*/
@@ -112,6 +71,29 @@ final class PersonApiControllerTest extends WebTestCase
$this->assertEquals($personId, $data['id']);
}
public static function dataGetPersonFromCenterA(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$personIds = $em->createQuery(sprintf(
'SELECT p.id FROM %s p JOIN p.centerCurrent pc JOIN pc.center c WHERE c.name = :center',
Person::class
))
->setParameter('center', 'Center A')
->setMaxResults(100)
->getScalarResult();
\shuffle($personIds);
yield \array_pop($personIds);
yield \array_pop($personIds);
yield \array_pop($personIds);
yield \array_pop($personIds);
}
/**
* @dataProvider dataGetPersonFromCenterB
*/
@@ -124,4 +106,22 @@ final class PersonApiControllerTest extends WebTestCase
$this->assertEquals(403, $response->getStatusCode());
}
public static function dataGetPersonFromCenterB(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$personIds = $em->createQuery(
sprintf('SELECT p.id FROM %s p JOIN p.centerCurrent pc JOIN pc.center c WHERE c.name = :center', Person::class)
)
->setParameter('center', 'Center B')
->setMaxResults(100)
->getScalarResult();
\shuffle($personIds);
yield \array_pop($personIds);
yield \array_pop($personIds);
}
}

View File

@@ -164,24 +164,6 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
}
}
/**
* Test the configurable fields are absent.
*
* @group configurable_fields
*/
public function testHiddenFielsAreAbsent()
{
$crawler = $this->client->request('GET', $this->editUrl);
$configurables = ['placeOfBirth', 'phonenumber', 'email',
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus', ];
$form = $crawler->selectButton('Submit')->form(); // ;
foreach ($configurables as $key) {
$this->assertFalse($form->has('chill_personbundle_person['.$key.']'));
}
}
/**
* provide valid values to test, with field name and
* a function to find the value back from person entity.
@@ -200,6 +182,24 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
];
}
/**
* Test the configurable fields are absent.
*
* @group configurable_fields
*/
public function testHiddenFielsAreAbsent()
{
$crawler = $this->client->request('GET', $this->editUrl);
$configurables = ['placeOfBirth', 'phonenumber', 'email',
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus', ];
$form = $crawler->selectButton('Submit')->form(); // ;
foreach ($configurables as $key) {
$this->assertFalse($form->has('chill_personbundle_person['.$key.']'));
}
}
/**
* Reload the person from the db.
*/

View File

@@ -23,6 +23,38 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/
final class PersonDuplicateControllerViewTest extends WebTestCase
{
/**
* @dataProvider providePersonData
*/
public function testViewDuplicatePerson(int $personId, int $person2Id): void
{
$client = self::createClient([], [
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password',
]);
$crawler = $client->request('GET', '/en/person/'.$personId.'/duplicate/view');
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Find duplicate")')->count());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginal")')->count());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count());
$crawler = $client->request('GET', '/en/person/'.$personId.'/duplicate/'.$person2Id.'/confirm');
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Old person")')->count());
$this->assertGreaterThan(0, $crawler->filter('html:contains("New person")')->count());
$crawler = $client->request('POST', '/en/person/'.$personId.'/duplicate/'.$person2Id.'/confirm', [
'chill_personbundle_person_confirm_duplicate[confirm]' => 1,
]);
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
}
public static function providePersonData(): iterable
{
self::bootKernel();
@@ -60,36 +92,4 @@ final class PersonDuplicateControllerViewTest extends WebTestCase
yield [$person->getId(), $person2->getId()];
}
/**
* @dataProvider providePersonData
*/
public function testViewDuplicatePerson(int $personId, int $person2Id): void
{
$client = self::createClient([], [
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password',
]);
$crawler = $client->request('GET', '/en/person/'.$personId.'/duplicate/view');
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Find duplicate")')->count());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginal")')->count());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Réginald")')->count());
$crawler = $client->request('GET', '/en/person/'.$personId.'/duplicate/'.$person2Id.'/confirm');
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$this->assertGreaterThan(0, $crawler->filter('html:contains("Old person")')->count());
$this->assertGreaterThan(0, $crawler->filter('html:contains("New person")')->count());
$crawler = $client->request('POST', '/en/person/'.$personId.'/duplicate/'.$person2Id.'/confirm', [
'chill_personbundle_person_confirm_duplicate[confirm]' => 1,
]);
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
}
}

View File

@@ -40,6 +40,19 @@ final class RelationshipApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
/**
* @dataProvider personProvider
*/
public function testGetRelationshipByPerson(int $personId)
{
self::ensureKernelShutdown();
$client = $this->getClientAuthenticated();
$client->request(Request::METHOD_GET, sprintf('/api/1.0/relations/relationship/by-person/%d.json', $personId));
$response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode(), 'Test to see that API response returns a status code 200');
}
public static function personProvider(): array
{
self::bootKernel();
@@ -75,42 +88,6 @@ final class RelationshipApiControllerTest extends WebTestCase
];
}
public static function relationProvider(): array
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$personIdWithoutRelations = $em->createQueryBuilder()
->select('p.id')
->from(Person::class, 'p')
->join('p.centerCurrent', 'center_current')
->join('center_current.center', 'c')
->where('c.name LIKE :name')
->andWhere('NOT EXISTS (SELECT 1 FROM '.Relationship::class.' r WHERE r.fromPerson = p OR r.toPerson = p)')
->setParameter('name', 'Center A')
->getQuery()
->setMaxResults(2)
->getResult();
self::ensureKernelShutdown();
return [
[$personIdWithoutRelations[0]['id'], $personIdWithoutRelations[1]['id'], self::getRandomRelation($em)->getId(), true],
];
}
/**
* @dataProvider personProvider
*/
public function testGetRelationshipByPerson(int $personId)
{
self::ensureKernelShutdown();
$client = $this->getClientAuthenticated();
$client->request(Request::METHOD_GET, sprintf('/api/1.0/relations/relationship/by-person/%d.json', $personId));
$response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode(), 'Test to see that API response returns a status code 200');
}
/**
* @dataProvider relationProvider
*/
@@ -137,6 +114,29 @@ final class RelationshipApiControllerTest extends WebTestCase
$this->assertEquals(200, $response->getStatusCode());
}
public static function relationProvider(): array
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
$personIdWithoutRelations = $em->createQueryBuilder()
->select('p.id')
->from(Person::class, 'p')
->join('p.centerCurrent', 'center_current')
->join('center_current.center', 'c')
->where('c.name LIKE :name')
->andWhere('NOT EXISTS (SELECT 1 FROM '.Relationship::class.' r WHERE r.fromPerson = p OR r.toPerson = p)')
->setParameter('name', 'Center A')
->getQuery()
->setMaxResults(2)
->getResult();
self::ensureKernelShutdown();
return [
[$personIdWithoutRelations[0]['id'], $personIdWithoutRelations[1]['id'], self::getRandomRelation($em)->getId(), true],
];
}
private static function getRandomRelation(EntityManagerInterface $em): Relation
{
if (null === self::$relations) {

View File

@@ -45,6 +45,24 @@ final class SocialWorkEvaluationApiControllerTest extends WebTestCase
$em->flush();
}
/**
* @dataProvider dataGenerateSocialActionWithEvaluations
*/
public function testListEvaluationBySocialAction(SocialAction $action, Evaluation $inactiveEvaluation): void
{
$client = $this->getClientAuthenticated();
$client->request('GET', sprintf('/api/1.0/person/social-work/evaluation/by-social-action/%d.json', $action->getId()));
$this->assertResponseIsSuccessful();
$content = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
$ids = array_map(static fn (array $item) => $item['id'], $content['results']);
$this->assertNotContains($inactiveEvaluation->getId(), $ids);
}
public static function dataGenerateSocialActionWithEvaluations(): iterable
{
self::bootKernel();
@@ -67,22 +85,4 @@ final class SocialWorkEvaluationApiControllerTest extends WebTestCase
yield [$socialAction, self::$evaluationToReset];
}
/**
* @dataProvider dataGenerateSocialActionWithEvaluations
*/
public function testListEvaluationBySocialAction(SocialAction $action, Evaluation $inactiveEvaluation): void
{
$client = $this->getClientAuthenticated();
$client->request('GET', sprintf('/api/1.0/person/social-work/evaluation/by-social-action/%d.json', $action->getId()));
$this->assertResponseIsSuccessful();
$content = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
$ids = array_map(static fn (array $item) => $item['id'], $content['results']);
$this->assertNotContains($inactiveEvaluation->getId(), $ids);
}
}

View File

@@ -21,30 +21,6 @@ use PHPUnit\Framework\TestCase;
*/
final class PersonCreateEventTest extends TestCase
{
public static function generateAltNames(): iterator
{
yield ['vinCENT', 'VINCENT'];
yield ['jean-marie', 'JEAN-MARIE'];
yield ['fastré', 'FASTRÉ'];
yield ['émile', 'ÉMILE'];
}
public static function generateNames(): iterator
{
yield ['émelie-marie', 'Émelie-Marie', 'lenaerts', 'LENAERTS'];
yield ['jean-marie', 'Jean-Marie', 'lenaerts', 'LENAERTS'];
yield ['vinCENT', 'Vincent', 'fastré', 'FASTRÉ'];
yield ['Vincent', 'Vincent', 'van Gogh', 'VAN GOGH'];
yield ['André marie', 'André Marie', 'Bah', 'BAH'];
}
/**
* @dataProvider generateAltNames
*/
@@ -61,6 +37,17 @@ final class PersonCreateEventTest extends TestCase
$this->assertEquals($altnameExpected, $personAltname->getLabel());
}
public static function generateAltNames(): iterator
{
yield ['vinCENT', 'VINCENT'];
yield ['jean-marie', 'JEAN-MARIE'];
yield ['fastré', 'FASTRÉ'];
yield ['émile', 'ÉMILE'];
}
/**
* @dataProvider generateNames
*/
@@ -78,4 +65,17 @@ final class PersonCreateEventTest extends TestCase
$this->assertEquals($firstnameExpected, $person->getFirstName());
$this->assertEquals($lastnameExpected, $person->getLastName());
}
public static function generateNames(): iterator
{
yield ['émelie-marie', 'Émelie-Marie', 'lenaerts', 'LENAERTS'];
yield ['jean-marie', 'Jean-Marie', 'lenaerts', 'LENAERTS'];
yield ['vinCENT', 'Vincent', 'fastré', 'FASTRÉ'];
yield ['Vincent', 'Vincent', 'van Gogh', 'VAN GOGH'];
yield ['André marie', 'André Marie', 'Bah', 'BAH'];
}
}

View File

@@ -77,31 +77,6 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
$this->normalizer = self::getContainer()->get(NormalizerInterface::class);
}
public static function dataGeneratorNormalizationNullOrNotNullHaveSameKeys(): iterable
{
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read']]];
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-household' => true]];
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-relations' => true]];
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-budget' => true]];
}
public static function generateData()
{
$person = new Person();
$person
->setFirstName('Renaud')
->setLastName('Mégane');
$expected = [...self::BLANK, 'firstName' => 'Renaud', 'lastName' => 'Mégane', 'text' => 'Renaud Mégane'];
yield [$person, $expected, 'partial normalization for a person'];
yield [null, self::BLANK, 'normalization for a null person'];
}
/**
* @dataProvider dataGeneratorNormalizationNullOrNotNullHaveSameKeys
*/
@@ -118,6 +93,17 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
);
}
public static function dataGeneratorNormalizationNullOrNotNullHaveSameKeys(): iterable
{
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read']]];
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-household' => true]];
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-relations' => true]];
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-budget' => true]];
}
/**
* @dataProvider generateData
*/
@@ -236,6 +222,20 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
]), $msg);
}
public static function generateData()
{
$person = new Person();
$person
->setFirstName('Renaud')
->setLastName('Mégane');
$expected = [...self::BLANK, 'firstName' => 'Renaud', 'lastName' => 'Mégane', 'text' => 'Renaud Mégane'];
yield [$person, $expected, 'partial normalization for a person'];
yield [null, self::BLANK, 'normalization for a null person'];
}
private function buildNormalizer(
?PersonRender $personRender = null,
?RelationshipRepository $relationshipRepository = null,

View File

@@ -62,6 +62,24 @@ class AccompanyingPeriodCalendarGenericDocProviderTest extends KernelTestCase
self::assertIsInt($nb);
}
public static function provideDataForAccompanyingPeriod(): iterable
{
self::bootKernel();
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
if (null === $period = $entityManager->createQuery('SELECT p FROM '.AccompanyingPeriod::class.' p ')
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException('There is no accompanying period');
}
yield [$period, null, null, null];
yield [$period, new \DateTimeImmutable('1 year ago'), null, null];
yield [$period, new \DateTimeImmutable('1 year ago'), new \DateTimeImmutable('6 month ago'), null];
yield [$period, new \DateTimeImmutable('1 year ago'), new \DateTimeImmutable('6 month ago'), 'text'];
yield [$period, null, null, 'text'];
yield [$period, null, new \DateTimeImmutable('6 month ago'), null];
}
/**
* @dataProvider provideDataForPerson
*/
@@ -120,22 +138,4 @@ class AccompanyingPeriodCalendarGenericDocProviderTest extends KernelTestCase
yield [$person, null, null, 'text'];
yield [$person, null, new \DateTimeImmutable('6 month ago'), null];
}
public static function provideDataForAccompanyingPeriod(): iterable
{
self::bootKernel();
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
if (null === $period = $entityManager->createQuery('SELECT p FROM '.AccompanyingPeriod::class.' p ')
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException('There is no accompanying period');
}
yield [$period, null, null, null];
yield [$period, new \DateTimeImmutable('1 year ago'), null, null];
yield [$period, new \DateTimeImmutable('1 year ago'), new \DateTimeImmutable('6 month ago'), null];
yield [$period, new \DateTimeImmutable('1 year ago'), new \DateTimeImmutable('6 month ago'), 'text'];
yield [$period, null, null, 'text'];
yield [$period, null, new \DateTimeImmutable('6 month ago'), null];
}
}

View File

@@ -28,6 +28,33 @@ final class TimelineAccompanyingPeriodTest extends WebTestCase
{
use PrepareClientTrait;
/**
* @dataProvider provideDataPersonWithAccompanyingPeriod
*/
public function testEntriesAreShown(mixed $personId): never
{
$this->markTestSkipped('page does not work');
$client = $this->getClientAuthenticated();
$crawler = $client->request('GET', "/en/person/{$personId}/timeline");
$this->assertTrue(
$client->getResponse()->isSuccessful(),
'the timeline page loads sucessfully'
);
$this->assertGreaterThan(
0,
$crawler->filter('.timeline div')->count(),
'the timeline page contains multiple div inside a .timeline element'
);
$this->assertStringContainsString(
'est ouvert',
$crawler->filter('.timeline')->text(),
"the text 'est ouvert' is present"
);
}
public static function provideDataPersonWithAccompanyingPeriod()
{
self::bootKernel();
@@ -55,31 +82,4 @@ final class TimelineAccompanyingPeriodTest extends WebTestCase
yield [\array_pop($personIds)['id']];
}
/**
* @dataProvider provideDataPersonWithAccompanyingPeriod
*/
public function testEntriesAreShown(mixed $personId): never
{
$this->markTestSkipped('page does not work');
$client = $this->getClientAuthenticated();
$crawler = $client->request('GET', "/en/person/{$personId}/timeline");
$this->assertTrue(
$client->getResponse()->isSuccessful(),
'the timeline page loads sucessfully'
);
$this->assertGreaterThan(
0,
$crawler->filter('.timeline div')->count(),
'the timeline page contains multiple div inside a .timeline element'
);
$this->assertStringContainsString(
'est ouvert',
$crawler->filter('.timeline')->text(),
"the text 'est ouvert' is present"
);
}
}

View File

@@ -25,6 +25,20 @@ use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
*/
final class MaxHolderValidatorTest extends ConstraintValidatorTestCase
{
/**
* @dataProvider provideInvalidHousehold
*/
public function testHouseholdInvalid(Household $household, mixed $parameters)
{
$constraint = $this->getConstraint();
$this->validator->validate($household, $constraint);
$this->buildViolation('msg')
->setParameters($parameters)
->assertRaised();
}
public static function provideInvalidHousehold()
{
$household = new Household();
@@ -59,20 +73,6 @@ final class MaxHolderValidatorTest extends ConstraintValidatorTestCase
];
}
/**
* @dataProvider provideInvalidHousehold
*/
public function testHouseholdInvalid(Household $household, mixed $parameters)
{
$constraint = $this->getConstraint();
$this->validator->validate($household, $constraint);
$this->buildViolation('msg')
->setParameters($parameters)
->assertRaised();
}
protected function createValidator()
{
return new MaxHolderValidator();