mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-08 07:44:59 +00:00
fix cs
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user