mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-29 10:05:03 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -20,24 +20,15 @@ use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Iterator;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use function array_map;
|
||||
use function array_pop;
|
||||
use function array_rand;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function json_decode;
|
||||
use function json_encode;
|
||||
|
||||
/**
|
||||
* Test api for AccompanyingCourseControllerTest.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
@@ -62,17 +53,17 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$period = new AccompanyingPeriod(new DateTime('1 week ago'));
|
||||
$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'));
|
||||
// $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' .
|
||||
$personIds = $em->createQuery('SELECT p.id FROM '.
|
||||
Person::class.' p JOIN p.centerCurrent cc'.
|
||||
' WHERE cc.center = :center')
|
||||
->setParameter('center', $center)
|
||||
->setMaxResults(100)
|
||||
@@ -82,7 +73,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
shuffle($personIds);
|
||||
|
||||
for ($i = 0; 2 > $i; ++$i) {
|
||||
$person = $em->getRepository(Person::class)->find(array_pop($personIds));
|
||||
$person = $em->getRepository(Person::class)->find(\array_pop($personIds));
|
||||
$period->addPerson($person);
|
||||
}
|
||||
|
||||
@@ -147,13 +138,13 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
$nbGenerated = 0;
|
||||
|
||||
while ($nbGenerated < $maxGenerated) {
|
||||
$id = array_pop($personIds)['id'];
|
||||
$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()];
|
||||
yield [\array_pop($personIds)['id'], $periods[\array_rand($periods)]->getId()];
|
||||
|
||||
++$nbGenerated;
|
||||
}
|
||||
@@ -211,21 +202,21 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
// create a random order
|
||||
shuffle($personIds);
|
||||
|
||||
$socialIssues = $em->createQuery('SELECT s FROM ' .
|
||||
SocialIssue::class . ' s ')
|
||||
$socialIssues = $em->createQuery('SELECT s FROM '.
|
||||
SocialIssue::class.' s ')
|
||||
->setMaxResults(10)
|
||||
->getResult();
|
||||
|
||||
$nbGenerated = 0;
|
||||
|
||||
while ($nbGenerated < $maxGenerated) {
|
||||
$id = array_pop($personIds)['id'];
|
||||
$id = \array_pop($personIds)['id'];
|
||||
|
||||
$person = $em->getRepository(Person::class)
|
||||
->find($id);
|
||||
$periods = $person->getAccompanyingPeriods();
|
||||
|
||||
yield [$periods[array_rand($periods)], $socialIssues[array_rand($socialIssues)]];
|
||||
yield [$periods[\array_rand($periods)], $socialIssues[\array_rand($socialIssues)]];
|
||||
|
||||
++$nbGenerated;
|
||||
}
|
||||
@@ -233,7 +224,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
|
||||
public function dataGenerateRandomRequestorValidData(): Iterator
|
||||
public function dataGenerateRandomRequestorValidData(): \Iterator
|
||||
{
|
||||
$dataLength = 2;
|
||||
$maxResults = 100;
|
||||
@@ -275,8 +266,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
// create a random order
|
||||
shuffle($personIds);
|
||||
|
||||
$thirdPartyIds = $em->createQuery('SELECT t.id FROM ' .
|
||||
ThirdParty::class . ' t ')
|
||||
$thirdPartyIds = $em->createQuery('SELECT t.id FROM '.
|
||||
ThirdParty::class.' t ')
|
||||
->setMaxResults($maxResults)
|
||||
->getScalarResult();
|
||||
|
||||
@@ -287,15 +278,15 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
|
||||
while ($i <= $dataLength) {
|
||||
$person = $em->getRepository(Person::class)
|
||||
->find(array_pop($personIds)['id']);
|
||||
->find(\array_pop($personIds)['id']);
|
||||
|
||||
if (count($person->getAccompanyingPeriods()) === 0) {
|
||||
if (0 === \count($person->getAccompanyingPeriods())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$period = $person->getAccompanyingPeriods()[0];
|
||||
|
||||
yield [$period, array_pop($personIds)['id'], array_pop($thirdPartyIds)['id']];
|
||||
yield [$period, \array_pop($personIds)['id'], \array_pop($thirdPartyIds)['id']];
|
||||
++$i;
|
||||
}
|
||||
|
||||
@@ -314,14 +305,14 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'person', 'id' => $personId], JSON_THROW_ON_ERROR)
|
||||
\json_encode(['type' => 'person', 'id' => $personId], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -332,17 +323,17 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
// check by deownloading the accompanying cours
|
||||
|
||||
$this->client->request(Request::METHOD_GET, sprintf('/api/1.0/person/accompanying-course/%d.json', $periodId));
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
$response = $this->client->getResponse();
|
||||
$data = json_decode((string) $response->getContent(), null, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), null, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
// check that the person id is contained
|
||||
$participationsPersonsIds = array_map(
|
||||
$participationsPersonsIds = \array_map(
|
||||
static fn ($participation) => $participation->person->id,
|
||||
$data->participations
|
||||
);
|
||||
@@ -356,14 +347,14 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'person', 'id' => $personId], JSON_THROW_ON_ERROR)
|
||||
\json_encode(['type' => 'person', 'id' => $personId], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -386,16 +377,16 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
json_encode(['type' => 'social_issue', 'id' => $si->getId()], JSON_THROW_ON_ERROR)
|
||||
\json_encode(['type' => 'social_issue', 'id' => $si->getId()], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
|
||||
$this->assertTrue(in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($this->client->getResponse()->getStatusCode() === 422) {
|
||||
if (422 === $this->client->getResponse()->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
$data = json_decode((string) $this->client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $this->client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertArrayHasKey('type', $data);
|
||||
$this->assertEquals('social_issue', $data['type']);
|
||||
@@ -406,10 +397,10 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
json_encode(['type' => 'social_issue', 'id' => $si->getId()], JSON_THROW_ON_ERROR)
|
||||
\json_encode(['type' => 'social_issue', 'id' => $si->getId()], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
|
||||
$this->assertTrue(in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,13 +412,13 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
$client->request(Request::METHOD_GET, sprintf('/api/1.0/person/accompanying-course/%d.json', $periodId));
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
$data = json_decode((string) $response->getContent(), null, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), null, 512, JSON_THROW_ON_ERROR);
|
||||
$this->assertEquals(
|
||||
$data->id,
|
||||
$periodId,
|
||||
@@ -453,13 +444,13 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'accompanying_period', 'emergency' => !$initialValueEmergency], JSON_THROW_ON_ERROR)
|
||||
\json_encode(['type' => 'accompanying_period', 'emergency' => !$initialValueEmergency], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -486,14 +477,14 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'accompanying_period_comment', 'content' => 'this is a text'])
|
||||
\json_encode(['type' => 'accompanying_period_comment', 'content' => 'this is a text'])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -505,12 +496,12 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'accompanying_period_comment', 'id' => $data['id']], JSON_THROW_ON_ERROR)
|
||||
\json_encode(['type' => 'accompanying_period_comment', 'id' => $data['id']], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -524,9 +515,9 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/confirm.json', $period->getId())
|
||||
);
|
||||
|
||||
$this->assertTrue(in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($this->client->getResponse()->getStatusCode() === 422) {
|
||||
if (422 === $this->client->getResponse()->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -545,7 +536,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/referrers-suggested.json', $periodId)
|
||||
);
|
||||
|
||||
$this->assertTrue(in_array($client->getResponse()->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($client->getResponse()->getStatusCode(), [200, 422], true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -563,14 +554,14 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'person', 'id' => $personId], JSON_THROW_ON_ERROR)
|
||||
\json_encode(['type' => 'person', 'id' => $personId], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -590,14 +581,14 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'thirdparty', 'id' => $thirdPartyId], JSON_THROW_ON_ERROR)
|
||||
\json_encode(['type' => 'thirdparty', 'id' => $thirdPartyId], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -616,9 +607,9 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/requestor.json', $period->getId())
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -644,14 +635,14 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'accompanying_period_resource', 'resource' => ['type' => 'person', 'id' => $personId]])
|
||||
\json_encode(['type' => 'accompanying_period_resource', 'resource' => ['type' => 'person', 'id' => $personId]])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -671,13 +662,13 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/requestor.json', $period->getId()),
|
||||
[],
|
||||
[],
|
||||
[], //server
|
||||
json_encode(['type' => 'accompanying_period_resource', 'id' => $resource->getId()], JSON_THROW_ON_ERROR)
|
||||
[], // server
|
||||
\json_encode(['type' => 'accompanying_period_resource', 'id' => $resource->getId()], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -688,14 +679,14 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server parameters
|
||||
json_encode(['type' => 'accompanying_period_resource', 'resource' => ['type' => 'thirdparty', 'id' => $thirdPartyId]])
|
||||
\json_encode(['type' => 'accompanying_period_resource', 'resource' => ['type' => 'thirdparty', 'id' => $thirdPartyId]])
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$data = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
|
||||
if ($response->getStatusCode() === 422) {
|
||||
if (422 === $response->getStatusCode()) {
|
||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||
}
|
||||
|
||||
@@ -715,11 +706,11 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
||||
sprintf('/api/1.0/person/accompanying-course/%d/requestor.json', $period->getId()),
|
||||
[],
|
||||
[],
|
||||
[], //server
|
||||
json_encode(['type' => 'accompanying_period_resource', 'id' => $resource->getId()], JSON_THROW_ON_ERROR)
|
||||
[], // server
|
||||
\json_encode(['type' => 'accompanying_period_resource', 'id' => $resource->getId()], JSON_THROW_ON_ERROR)
|
||||
);
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue(in_array($response->getStatusCode(), [200, 422], true));
|
||||
$this->assertTrue(\in_array($response->getStatusCode(), [200, 422], true));
|
||||
}
|
||||
|
||||
public function testShow404()
|
||||
|
@@ -16,17 +16,13 @@ use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Iterator;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use function array_pop;
|
||||
use function count;
|
||||
use function preg_match;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AccompanyingCourseControllerTest extends WebTestCase
|
||||
@@ -45,28 +41,28 @@ final class AccompanyingCourseControllerTest extends WebTestCase
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
|
||||
public function dataGenerateRandomUsers(): Iterator
|
||||
public function dataGenerateRandomUsers(): \Iterator
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$period = new AccompanyingPeriod(new DateTime('1 week ago'));
|
||||
$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'));
|
||||
// $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 ' .
|
||||
$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)];
|
||||
yield [\array_pop($personIds), \array_pop($personIds)];
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
@@ -78,7 +74,7 @@ final class AccompanyingCourseControllerTest extends WebTestCase
|
||||
$this->assertResponseRedirects();
|
||||
$location = $this->client->getResponse()->headers->get('Location');
|
||||
|
||||
$this->assertEquals(1, preg_match('|^\\/[^\\/]+\\/parcours/([\\d]+)/edit$|', (string) $location));
|
||||
$this->assertEquals(1, \preg_match('|^\\/[^\\/]+\\/parcours/([\\d]+)/edit$|', (string) $location));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +93,7 @@ final class AccompanyingCourseControllerTest extends WebTestCase
|
||||
$location = $this->client->getResponse()->headers->get('Location');
|
||||
$matches = [];
|
||||
|
||||
$this->assertEquals(1, preg_match('|^\\/[^\\/]+\\/parcours/([\\d]+)/edit$|', (string) $location, $matches));
|
||||
$this->assertEquals(1, \preg_match('|^\\/[^\\/]+\\/parcours/([\\d]+)/edit$|', (string) $location, $matches));
|
||||
$id = $matches[1];
|
||||
|
||||
$period = self::$container->get(EntityManagerInterface::class)
|
||||
@@ -106,6 +102,6 @@ final class AccompanyingCourseControllerTest extends WebTestCase
|
||||
|
||||
$this->assertNotNull($period);
|
||||
|
||||
$this->assertEquals(2, count($period->getParticipations()));
|
||||
$this->assertEquals(2, \count($period->getParticipations()));
|
||||
}
|
||||
}
|
||||
|
@@ -13,11 +13,8 @@ namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use LogicalException;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
* Test the creation or deletion of accompanying periods.
|
||||
@@ -26,6 +23,7 @@ use function array_key_exists;
|
||||
* closed) starting the 2015-01-05.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
@@ -74,7 +72,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
$center = self::$em->getRepository(\Chill\MainBundle\Entity\Center::class)
|
||||
->findOneBy(['name' => 'Center A']);
|
||||
|
||||
$this->person = (new Person(new DateTime('2015-01-05')))
|
||||
$this->person = (new Person(new \DateTime('2015-01-05')))
|
||||
->setFirstName('Roland')
|
||||
->setLastName('Gallorime')
|
||||
->setCenter($center)
|
||||
@@ -108,7 +106,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
public function testAddNewPeriodBeforeActual()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
. $this->person->getId() . '/accompanying-period/create');
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
@@ -122,7 +120,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
|
||||
$this->assertTrue(
|
||||
$this->client->getResponse()->isRedirect(
|
||||
'/fr/person/' . $this->person->getId() . '/accompanying-period'
|
||||
'/fr/person/'.$this->person->getId().'/accompanying-period'
|
||||
),
|
||||
'the server redirects to /accompanying-period page'
|
||||
);
|
||||
@@ -149,20 +147,20 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
public function testClosingCurrentPeriod()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
. $this->person->getId() . '/accompanying-period/close');
|
||||
.$this->person->getId().'/accompanying-period/close');
|
||||
|
||||
$form = $crawler->selectButton('Clôre la période')->form();
|
||||
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue((new DateTime('2015-02-01'))->format('d-m-Y'));
|
||||
->setValue((new \DateTime('2015-02-01'))->format('d-m-Y'));
|
||||
|
||||
$cr = $this->client->submit($form);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->client->getResponse()->isRedirect(
|
||||
'/fr/person/' . $this->person->getId() . '/accompanying-period'
|
||||
'/fr/person/'.$this->person->getId().'/accompanying-period'
|
||||
),
|
||||
'the server redirects to /accompanying-period page'
|
||||
);
|
||||
@@ -189,14 +187,14 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
public function testClosingCurrentPeriodWithDateClosingBeforeOpeningFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
. $this->person->getId() . '/accompanying-period/close');
|
||||
.$this->person->getId().'/accompanying-period/close');
|
||||
|
||||
$form = $crawler->selectButton('Clôre la période')->form();
|
||||
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
->setValue($this->getLastValueOnClosingMotive($form));
|
||||
$form->get(self::CLOSING_INPUT)
|
||||
->setValue((new DateTime('2014-01-01'))->format('d-m-Y'));
|
||||
->setValue((new \DateTime('2014-01-01'))->format('d-m-Y'));
|
||||
|
||||
$crawlerResponse = $this->client->submit($form);
|
||||
|
||||
@@ -236,7 +234,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
]);
|
||||
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
. $this->person->getId() . '/accompanying-period/create');
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
@@ -272,11 +270,11 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testCreatePeriodWithClosingAfterCurrentFails(): never
|
||||
{
|
||||
$this->markTestSkipped('Multiple period may now cover. This test is kept ' .
|
||||
$this->markTestSkipped('Multiple period may now cover. This test is kept '.
|
||||
'in case of a configuration may add this feature again');
|
||||
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
. $this->person->getId() . '/accompanying-period/create');
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton("Créer une période d'accompagnement")->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
@@ -312,7 +310,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
public function testCreatePeriodWithClosingBeforeOpeningFails()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
. $this->person->getId() . '/accompanying-period/create');
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
@@ -358,7 +356,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
]);
|
||||
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
. $this->person->getId() . '/accompanying-period/create');
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
@@ -404,7 +402,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
]);
|
||||
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
. $this->person->getId() . '/accompanying-period/create');
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton('Créer une période d\'accompagnement')->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
@@ -440,11 +438,11 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testCreatePeriodWithOpeningAndClosingAfterCurrentFails(): never
|
||||
{
|
||||
$this->markTestSkipped('Multiple period may now cover. This test is kept ' .
|
||||
$this->markTestSkipped('Multiple period may now cover. This test is kept '.
|
||||
'in case of a configuration may add this feature again');
|
||||
|
||||
$crawler = $this->client->request('GET', '/fr/person/'
|
||||
. $this->person->getId() . '/accompanying-period/create');
|
||||
.$this->person->getId().'/accompanying-period/create');
|
||||
|
||||
$form = $crawler->selectButton("Créer une période d'accompagnement")->form();
|
||||
$form->get(self::CLOSING_MOTIVE_INPUT)
|
||||
@@ -489,7 +487,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
|
||||
// close the current period
|
||||
$period = $this->person->getOpenedAccompanyingPeriod();
|
||||
$period->setClosingDate(new DateTime('2015-02-05'));
|
||||
$period->setClosingDate(new \DateTime('2015-02-05'));
|
||||
$this->person->close($period);
|
||||
|
||||
$this->generatePeriods([
|
||||
@@ -503,7 +501,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
$periods = $this->person->getAccompanyingPeriodsOrdered();
|
||||
/** @var Criteria $criteria */
|
||||
$criteria = Criteria::create();
|
||||
//$criteria->where(Criteria::expr()->eq('openingDate', \DateTime::createFromFormat()))
|
||||
// $criteria->where(Criteria::expr()->eq('openingDate', \DateTime::createFromFormat()))
|
||||
$firstPeriod = reset($periods);
|
||||
$lastPeriod = end($periods);
|
||||
|
||||
@@ -546,15 +544,14 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
protected function generatePeriods(array $periods)
|
||||
{
|
||||
foreach ($periods as $periodDef) {
|
||||
$period = new AccompanyingPeriod(new DateTime($periodDef['openingDate']));
|
||||
$period = new AccompanyingPeriod(new \DateTime($periodDef['openingDate']));
|
||||
|
||||
if (array_key_exists('closingDate', $periodDef)) {
|
||||
if (!array_key_exists('closingMotive', $periodDef)) {
|
||||
throw new LogicalException('you must define a closing '
|
||||
. 'motive into your periods fixtures');
|
||||
if (\array_key_exists('closingDate', $periodDef)) {
|
||||
if (!\array_key_exists('closingMotive', $periodDef)) {
|
||||
throw new \LogicalException('you must define a closing motive into your periods fixtures');
|
||||
}
|
||||
|
||||
$period->setClosingDate(new DateTime($periodDef['closingDate']))
|
||||
$period->setClosingDate(new \DateTime($periodDef['closingDate']))
|
||||
->setClosingMotive($periodDef['closingMotive']);
|
||||
}
|
||||
|
||||
@@ -571,7 +568,7 @@ final class AccompanyingPeriodControllerTest extends WebTestCase
|
||||
* @var \Symfony\Component\DomCrawler\Form The form
|
||||
*
|
||||
* @return Chill\PersonBundle\Entity\AccompanyingPeriod The last value of closing
|
||||
* motive
|
||||
* motive
|
||||
*/
|
||||
protected function getLastValueOnClosingMotive(\Symfony\Component\DomCrawler\Form $form)
|
||||
{
|
||||
|
@@ -16,6 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AccompanyingPeriodRegulationListControllerTest extends WebTestCase
|
||||
|
@@ -15,22 +15,16 @@ use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\AddressReference;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use function array_map;
|
||||
use function array_pop;
|
||||
use function random_int;
|
||||
use function shuffle;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class HouseholdApiControllerTest extends WebTestCase
|
||||
@@ -64,11 +58,11 @@ final class HouseholdApiControllerTest extends WebTestCase
|
||||
->getQuery()->getSingleScalarResult();
|
||||
|
||||
if (0 === $nbReference) {
|
||||
throw new RuntimeException('any reference found. Add a reference in database to perform this test');
|
||||
throw new \RuntimeException('any reference found. Add a reference in database to perform this test');
|
||||
}
|
||||
|
||||
$reference = $em->createQueryBuilder()->select('ar')->from(AddressReference::class, 'ar')
|
||||
->setFirstResult(random_int(0, $nbReference - 1))
|
||||
->setFirstResult(\random_int(0, $nbReference - 1))
|
||||
->setMaxResults(1)
|
||||
->getQuery()->getSingleResult();
|
||||
|
||||
@@ -79,14 +73,14 @@ final class HouseholdApiControllerTest extends WebTestCase
|
||||
$em->persist($p);
|
||||
$h = new Household();
|
||||
$h->addMember($m = (new HouseholdMember())->setPerson($p));
|
||||
$h->addAddress($a = Address::createFromAddressReference($reference)->setValidFrom(new DateTime('today')));
|
||||
$h->addAddress($a = Address::createFromAddressReference($reference)->setValidFrom(new \DateTime('today')));
|
||||
$em->persist($a);
|
||||
$em->persist($m);
|
||||
$em->persist($h);
|
||||
|
||||
$em->flush();
|
||||
|
||||
$this->toDelete = $this->toDelete + [
|
||||
$this->toDelete += [
|
||||
[HouseholdMember::class, $m->getId()],
|
||||
[User::class, $p->getId()],
|
||||
[Household::class, $h->getId()],
|
||||
@@ -119,13 +113,13 @@ final class HouseholdApiControllerTest extends WebTestCase
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
shuffle($householdIds);
|
||||
\shuffle($householdIds);
|
||||
|
||||
yield [array_pop($householdIds)['id']];
|
||||
yield [\array_pop($householdIds)['id']];
|
||||
|
||||
yield [array_pop($householdIds)['id']];
|
||||
yield [\array_pop($householdIds)['id']];
|
||||
|
||||
yield [array_pop($householdIds)['id']];
|
||||
yield [\array_pop($householdIds)['id']];
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
@@ -138,7 +132,7 @@ final class HouseholdApiControllerTest extends WebTestCase
|
||||
->createQueryBuilder();
|
||||
|
||||
$personIds = $qb
|
||||
->select("p.id AS pid")
|
||||
->select('p.id AS pid')
|
||||
->from(Person::class, 'p')
|
||||
->where(
|
||||
$qb->expr()->gte('SIZE(p.accompanyingPeriodParticipations)', 2)
|
||||
@@ -169,7 +163,7 @@ final class HouseholdApiControllerTest extends WebTestCase
|
||||
$this->assertArrayHasKey('count', $data);
|
||||
$this->assertArrayHasKey('results', $data);
|
||||
|
||||
$householdIds = array_map(static fn ($r) => $r['id'], $data['results']);
|
||||
$householdIds = \array_map(static fn ($r) => $r['id'], $data['results']);
|
||||
|
||||
$this->assertContains($expectedHouseholdId, $householdIds);
|
||||
}
|
||||
|
@@ -13,17 +13,14 @@ namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use function array_pop;
|
||||
use function shuffle;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class HouseholdControllerTest extends WebTestCase
|
||||
@@ -48,7 +45,7 @@ final class HouseholdControllerTest extends WebTestCase
|
||||
$em = self::$container->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)
|
||||
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)
|
||||
@@ -58,13 +55,13 @@ final class HouseholdControllerTest extends WebTestCase
|
||||
throw new \RuntimeException('no household ids with center "Center A"');
|
||||
}
|
||||
|
||||
shuffle($ids);
|
||||
\shuffle($ids);
|
||||
|
||||
yield [array_pop($ids)['id']];
|
||||
yield [\array_pop($ids)['id']];
|
||||
|
||||
yield [array_pop($ids)['id']];
|
||||
yield [\array_pop($ids)['id']];
|
||||
|
||||
yield [array_pop($ids)['id']];
|
||||
yield [\array_pop($ids)['id']];
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
@@ -117,8 +114,8 @@ final class HouseholdControllerTest extends WebTestCase
|
||||
|
||||
$form['household[commentMembers][comment]'] = 'This is a text **generated** by automatic tests';
|
||||
$form['household[waitingForBirth]']->tick();
|
||||
$form['household[waitingForBirthDate]'] = (new DateTime('today'))
|
||||
->add(new DateInterval('P1M'))->format('Y-m-d');
|
||||
$form['household[waitingForBirthDate]'] = (new \DateTime('today'))
|
||||
->add(new \DateInterval('P1M'))->format('Y-m-d');
|
||||
|
||||
$this->client->submit($form);
|
||||
|
||||
|
@@ -16,34 +16,26 @@ use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Iterator;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use function array_pop;
|
||||
use function count;
|
||||
use function json_decode;
|
||||
use function json_encode;
|
||||
use function random_int;
|
||||
use function shuffle;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class HouseholdMemberControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
public function provideValidDataEditMember(): Iterator
|
||||
public function provideValidDataEditMember(): \Iterator
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->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))
|
||||
$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();
|
||||
|
||||
@@ -51,19 +43,19 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
throw new \RuntimeException("no memberships for person associated to 'Center A'");
|
||||
}
|
||||
|
||||
shuffle($membershipIds);
|
||||
\shuffle($membershipIds);
|
||||
|
||||
yield [array_pop($membershipIds)['id']];
|
||||
yield [\array_pop($membershipIds)['id']];
|
||||
}
|
||||
|
||||
public function provideValidDataMove(): Iterator
|
||||
public function provideValidDataMove(): \Iterator
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
$yesterday = new DateTimeImmutable('yesterday');
|
||||
$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)
|
||||
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)
|
||||
@@ -73,20 +65,20 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
throw new \RuntimeException('no person associated with "Center A"');
|
||||
}
|
||||
|
||||
shuffle($personIds);
|
||||
\shuffle($personIds);
|
||||
|
||||
$household = new Household();
|
||||
$em->persist($household);
|
||||
$em->flush();
|
||||
|
||||
$positions = $em->createQuery('SELECT pos.id FROM ' . Position::class . ' pos ' .
|
||||
$positions = $em->createQuery('SELECT pos.id FROM '.Position::class.' pos '.
|
||||
'WHERE pos.shareHouseHold = TRUE')
|
||||
->getResult();
|
||||
|
||||
$i = 0;
|
||||
|
||||
do {
|
||||
$id = array_pop($personIds)['id'];
|
||||
$id = \array_pop($personIds)['id'];
|
||||
$person = self::$container->get(EntityManagerInterface::class)
|
||||
->getRepository(Person::class)
|
||||
->find($id);
|
||||
@@ -103,8 +95,8 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
yield [
|
||||
$id,
|
||||
$household->getId(),
|
||||
$positions[random_int(0, count($positions) - 1)]['id'],
|
||||
new DateTimeImmutable('tomorrow'),
|
||||
$positions[\random_int(0, \count($positions) - 1)]['id'],
|
||||
new \DateTimeImmutable('tomorrow'),
|
||||
];
|
||||
}
|
||||
} while (1 >= $i);
|
||||
@@ -135,7 +127,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
/**
|
||||
* @dataProvider provideValidDataMove
|
||||
*/
|
||||
public function testLeaveWithoutHousehold(mixed $personId, mixed $householdId, mixed $positionId, DateTimeInterface $date)
|
||||
public function testLeaveWithoutHousehold(mixed $personId, mixed $householdId, mixed $positionId, \DateTimeInterface $date)
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
@@ -145,7 +137,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server
|
||||
json_encode(
|
||||
\json_encode(
|
||||
[
|
||||
'concerned' => [
|
||||
[
|
||||
@@ -154,7 +146,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
'id' => $personId,
|
||||
],
|
||||
'start_date' => [
|
||||
'datetime' => $date->format(DateTimeInterface::RFC3339),
|
||||
'datetime' => $date->format(\DateTimeInterface::RFC3339),
|
||||
],
|
||||
'position' => [
|
||||
'type' => 'household_position',
|
||||
@@ -175,7 +167,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
$client->getResponse()->getStatusCode()
|
||||
);
|
||||
|
||||
$data = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertEquals(null, $data);
|
||||
}
|
||||
@@ -183,7 +175,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
/**
|
||||
* @dataProvider provideValidDataMove
|
||||
*/
|
||||
public function testMoveMember(mixed $personId, mixed $householdId, mixed $positionId, DateTimeInterface $date)
|
||||
public function testMoveMember(mixed $personId, mixed $householdId, mixed $positionId, \DateTimeInterface $date)
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
@@ -193,7 +185,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server
|
||||
json_encode(
|
||||
\json_encode(
|
||||
[
|
||||
'concerned' => [
|
||||
[
|
||||
@@ -202,7 +194,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
'id' => $personId,
|
||||
],
|
||||
'start_date' => [
|
||||
'datetime' => $date->format(DateTimeInterface::RFC3339),
|
||||
'datetime' => $date->format(\DateTimeInterface::RFC3339),
|
||||
],
|
||||
'position' => [
|
||||
'type' => 'household_position',
|
||||
@@ -230,7 +222,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
/**
|
||||
* @dataProvider provideValidDataMove
|
||||
*/
|
||||
public function testMoveMemberToNewHousehold(mixed $personId, mixed $householdId, mixed $positionId, DateTimeInterface $date)
|
||||
public function testMoveMemberToNewHousehold(mixed $personId, mixed $householdId, mixed $positionId, \DateTimeInterface $date)
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
@@ -240,7 +232,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
[], // parameters
|
||||
[], // files
|
||||
[], // server
|
||||
json_encode(
|
||||
\json_encode(
|
||||
[
|
||||
'concerned' => [
|
||||
[
|
||||
@@ -249,7 +241,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
'id' => $personId,
|
||||
],
|
||||
'start_date' => [
|
||||
'datetime' => $date->format(DateTimeInterface::RFC3339),
|
||||
'datetime' => $date->format(\DateTimeInterface::RFC3339),
|
||||
],
|
||||
'position' => [
|
||||
'type' => 'household_position',
|
||||
@@ -272,14 +264,14 @@ final class HouseholdMemberControllerTest extends WebTestCase
|
||||
$client->getResponse()->getStatusCode()
|
||||
);
|
||||
|
||||
$data = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertIsArray($data);
|
||||
$this->assertArrayHasKey('members', $data);
|
||||
$this->assertIsArray($data['members']);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count($data['members']),
|
||||
\count($data['members']),
|
||||
'assert new household count one member'
|
||||
);
|
||||
$this->assertArrayHasKey('person', $data['members'][0]);
|
||||
|
@@ -16,6 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PersonAddressControllerTest extends WebTestCase
|
||||
@@ -91,8 +92,8 @@ final class PersonAddressControllerTest extends WebTestCase
|
||||
*/
|
||||
public function testCreateAddress()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/person/' .
|
||||
self::$person->getId() . '/address/new');
|
||||
$crawler = $this->client->request('GET', '/fr/person/'.
|
||||
self::$person->getId().'/address/new');
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful());
|
||||
|
||||
@@ -134,8 +135,8 @@ final class PersonAddressControllerTest extends WebTestCase
|
||||
|
||||
public function testEmptyList()
|
||||
{
|
||||
$crawler = $this->client->request('GET', '/fr/person/' .
|
||||
self::$person->getId() . '/address/list');
|
||||
$crawler = $this->client->request('GET', '/fr/person/'.
|
||||
self::$person->getId().'/address/list');
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful());
|
||||
|
||||
@@ -155,8 +156,8 @@ final class PersonAddressControllerTest extends WebTestCase
|
||||
$this->refreshPerson();
|
||||
$address = self::$person->getLastAddress();
|
||||
|
||||
$crawler = $this->client->request('GET', '/fr/person/' . self::$person->getId()
|
||||
. '/address/' . $address->getId() . '/edit');
|
||||
$crawler = $this->client->request('GET', '/fr/person/'.self::$person->getId()
|
||||
.'/address/'.$address->getId().'/edit');
|
||||
|
||||
$this->assertTrue($this->client->getResponse()->isSuccessful());
|
||||
|
||||
|
@@ -14,60 +14,57 @@ namespace Chill\PersonBundle\Tests\Controller;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Iterator;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use function array_pop;
|
||||
use function json_decode;
|
||||
use function shuffle;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PersonApiControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
public function dataGetPersonFromCenterA(): Iterator
|
||||
public function dataGetPersonFromCenterA(): \Iterator
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->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",
|
||||
'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);
|
||||
\shuffle($personIds);
|
||||
|
||||
yield array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
|
||||
yield array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
|
||||
yield array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
|
||||
yield array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
}
|
||||
|
||||
public function dataGetPersonFromCenterB(): Iterator
|
||||
public function dataGetPersonFromCenterB(): \Iterator
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->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)
|
||||
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);
|
||||
\shuffle($personIds);
|
||||
|
||||
yield array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
|
||||
yield array_pop($personIds);
|
||||
yield \array_pop($personIds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +104,7 @@ final class PersonApiControllerTest extends WebTestCase
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
$data = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertArrayHasKey('type', $data);
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
|
@@ -12,18 +12,16 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\DomCrawler\Form;
|
||||
use function count;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Test creation and deletion for persons.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PersonControllerCreateTest extends WebTestCase
|
||||
@@ -51,7 +49,7 @@ final class PersonControllerCreateTest extends WebTestCase
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
//remove two people created during test
|
||||
// remove two people created during test
|
||||
$jesus = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)
|
||||
->findOneBy(['firstName' => 'God']);
|
||||
|
||||
@@ -120,15 +118,15 @@ final class PersonControllerCreateTest extends WebTestCase
|
||||
);
|
||||
$this->assertEquals(
|
||||
3,
|
||||
count($genderType->availableOptionValues()),
|
||||
\count($genderType->availableOptionValues()),
|
||||
'The gender input has three options: man, women and undefined'
|
||||
);
|
||||
$this->assertTrue(
|
||||
in_array('man', $genderType->availableOptionValues(), true),
|
||||
\in_array('man', $genderType->availableOptionValues(), true),
|
||||
'gender has "homme" option'
|
||||
);
|
||||
$this->assertTrue(
|
||||
in_array('woman', $genderType->availableOptionValues(), true),
|
||||
\in_array('woman', $genderType->availableOptionValues(), true),
|
||||
'gender has "femme" option'
|
||||
);
|
||||
$this->assertFalse($genderType->hasValue(), 'The gender input is not checked');
|
||||
@@ -143,11 +141,11 @@ final class PersonControllerCreateTest extends WebTestCase
|
||||
|
||||
$crawler = $client->request('GET', '/fr/person/new');
|
||||
|
||||
//test the page is loaded before continuing
|
||||
// test the page is loaded before continuing
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $crawler->selectButton("Créer l'usager")->form();
|
||||
$form = $this->fillAValidCreationForm($form, 'Charline', 'dd', new DateTime('1970-10-15'));
|
||||
$form = $this->fillAValidCreationForm($form, 'Charline', 'dd', new \DateTime('1970-10-15'));
|
||||
$client->submit($form);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
@@ -156,7 +154,7 @@ final class PersonControllerCreateTest extends WebTestCase
|
||||
'check that the page has detected the lastname of a person existing in database'
|
||||
);
|
||||
|
||||
//inversion
|
||||
// inversion
|
||||
$form = $crawler->selectButton("Créer l'usager")->form();
|
||||
$form = $this->fillAValidCreationForm($form, 'dd', 'Charline');
|
||||
$client->submit($form);
|
||||
@@ -224,12 +222,12 @@ final class PersonControllerCreateTest extends WebTestCase
|
||||
Form &$creationForm,
|
||||
string $firstname = 'God',
|
||||
string $lastname = 'Jesus',
|
||||
?DateTime $birthdate = null
|
||||
\DateTime $birthdate = null
|
||||
) {
|
||||
$creationForm->get(self::FIRSTNAME_INPUT)->setValue($firstname . '_' . uniqid());
|
||||
$creationForm->get(self::LASTNAME_INPUT)->setValue($lastname . '_' . uniqid());
|
||||
$creationForm->get(self::FIRSTNAME_INPUT)->setValue($firstname.'_'.uniqid());
|
||||
$creationForm->get(self::LASTNAME_INPUT)->setValue($lastname.'_'.uniqid());
|
||||
$creationForm->get(self::GENDER_INPUT)->select('man');
|
||||
$date = $birthdate ?? new DateTime('1947-02-01');
|
||||
$date = $birthdate ?? new \DateTime('1947-02-01');
|
||||
$creationForm->get(self::BIRTHDATE_INPUT)->setValue($date->format('Y-m-d'));
|
||||
|
||||
return $creationForm;
|
||||
|
@@ -16,9 +16,7 @@ use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Closure;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\Constraint\StringContains;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
@@ -28,6 +26,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
* As I am logged in as "center a_social"
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PersonControllerUpdateTest extends WebTestCase
|
||||
@@ -157,7 +156,7 @@ final class PersonControllerUpdateTest extends WebTestCase
|
||||
|
||||
$alerts = $crawler->filter('.alert-danger');
|
||||
|
||||
self::assertEquals(1, $alerts->count(), "there is an alert message displayed on the page");
|
||||
self::assertEquals(1, $alerts->count(), 'there is an alert message displayed on the page');
|
||||
}
|
||||
|
||||
public static function providePerson(): iterable
|
||||
|
@@ -11,10 +11,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Controller;
|
||||
|
||||
//ini_set('memory_limit', '-1');
|
||||
// ini_set('memory_limit', '-1');
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Closure;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
@@ -23,6 +22,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
* As I am logged in as "center a_social"
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
|
||||
@@ -63,8 +63,8 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
|
||||
$this->em->persist($this->person);
|
||||
$this->em->flush();
|
||||
|
||||
$this->editUrl = '/en/person/' . $this->person->getId() . '/general/edit';
|
||||
$this->viewUrl = '/en/person/' . $this->person->getId() . '/general';
|
||||
$this->editUrl = '/en/person/'.$this->person->getId().'/general/edit';
|
||||
$this->viewUrl = '/en/person/'.$this->person->getId().'/general';
|
||||
|
||||
$this->client = self::createClient(
|
||||
[
|
||||
@@ -109,13 +109,13 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
|
||||
* @param string $field
|
||||
* @param string $value
|
||||
*/
|
||||
public function testEditTextField($field, $value, Closure $callback)
|
||||
public function testEditTextField($field, $value, \Closure $callback)
|
||||
{
|
||||
$crawler = $this->client->request('GET', $this->editUrl);
|
||||
|
||||
$form = $crawler->selectButton('Submit')
|
||||
->form();
|
||||
//transform countries into value if needed
|
||||
// transform countries into value if needed
|
||||
switch ($field) {
|
||||
case 'nationality':
|
||||
case 'countryOfBirth':
|
||||
@@ -133,7 +133,7 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
|
||||
$transformedValue = $value;
|
||||
}
|
||||
|
||||
$form->get('chill_personbundle_person[' . $field . ']')
|
||||
$form->get('chill_personbundle_person['.$field.']')
|
||||
->setValue($transformedValue);
|
||||
|
||||
$this->client->submit($form);
|
||||
@@ -146,7 +146,7 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$callback($this->person),
|
||||
'the value ' . $field . ' is updated in db'
|
||||
'the value '.$field.' is updated in db'
|
||||
);
|
||||
|
||||
$crawler = $this->client->followRedirect();
|
||||
@@ -160,7 +160,7 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
|
||||
|| 'gender' === $field) {
|
||||
// we do not perform test on the web page contents.
|
||||
} else {
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("' . $value . '")')->count());
|
||||
$this->assertGreaterThan(0, $crawler->filter('html:contains("'.$value.'")')->count());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,10 +175,10 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
|
||||
|
||||
$configurables = ['placeOfBirth', 'phonenumber', 'email',
|
||||
'countryOfBirth', 'nationality', 'spokenLanguages', 'maritalStatus', ];
|
||||
$form = $crawler->selectButton('Submit')->form(); //;
|
||||
$form = $crawler->selectButton('Submit')->form(); // ;
|
||||
|
||||
foreach ($configurables as $key) {
|
||||
$this->assertFalse($form->has('chill_personbundle_person[' . $key . ']'));
|
||||
$this->assertFalse($form->has('chill_personbundle_person['.$key.']'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PersonControllerViewTest extends WebTestCase
|
||||
|
@@ -16,6 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PersonControllerViewWithHiddenFieldsTest extends WebTestCase
|
||||
@@ -31,26 +32,26 @@ final class PersonControllerViewWithHiddenFieldsTest extends WebTestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
/**
|
||||
self::bootKernel(['environment' => 'test_with_hidden_fields']);
|
||||
|
||||
$this->em = self::$kernel->getContainer()
|
||||
->get('doctrine.orm.entity_manager');
|
||||
|
||||
$center = $this->em->getRepository(\Chill\MainBundle\Entity\Center::class)
|
||||
->findOneBy(['name' => 'Center A']);
|
||||
|
||||
$this->person = (new Person())
|
||||
->setLastName('Tested Person')
|
||||
->setFirstName('Réginald')
|
||||
->setCenter($center)
|
||||
->setGender(Person::MALE_GENDER);
|
||||
|
||||
$this->em->persist($this->person);
|
||||
$this->em->flush();
|
||||
|
||||
$this->viewUrl = '/en/person/' . $this->person->getId() . '/general';
|
||||
*/
|
||||
/*
|
||||
* self::bootKernel(['environment' => 'test_with_hidden_fields']);
|
||||
*
|
||||
* $this->em = self::$kernel->getContainer()
|
||||
* ->get('doctrine.orm.entity_manager');
|
||||
*
|
||||
* $center = $this->em->getRepository(\Chill\MainBundle\Entity\Center::class)
|
||||
* ->findOneBy(['name' => 'Center A']);
|
||||
*
|
||||
* $this->person = (new Person())
|
||||
* ->setLastName('Tested Person')
|
||||
* ->setFirstName('Réginald')
|
||||
* ->setCenter($center)
|
||||
* ->setGender(Person::MALE_GENDER);
|
||||
*
|
||||
* $this->em->persist($this->person);
|
||||
* $this->em->flush();
|
||||
*
|
||||
* $this->viewUrl = '/en/person/' . $this->person->getId() . '/general';
|
||||
*/
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
|
@@ -18,6 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PersonDuplicateControllerViewTest extends WebTestCase
|
||||
@@ -62,7 +63,6 @@ final class PersonDuplicateControllerViewTest extends WebTestCase
|
||||
|
||||
/**
|
||||
* @dataProvider providePersonData
|
||||
* @return void
|
||||
*/
|
||||
public function testViewDuplicatePerson(int $personId, int $person2Id): void
|
||||
{
|
||||
@@ -71,7 +71,7 @@ final class PersonDuplicateControllerViewTest extends WebTestCase
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
]);
|
||||
|
||||
$crawler = $client->request('GET', '/en/person/' . $personId . '/duplicate/view');
|
||||
$crawler = $client->request('GET', '/en/person/'.$personId.'/duplicate/view');
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
|
||||
@@ -79,14 +79,14 @@ final class PersonDuplicateControllerViewTest extends WebTestCase
|
||||
$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');
|
||||
$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', [
|
||||
$crawler = $client->request('POST', '/en/person/'.$personId.'/duplicate/'.$person2Id.'/confirm', [
|
||||
'chill_personbundle_person_confirm_duplicate[confirm]' => 1,
|
||||
]);
|
||||
$response = $client->getResponse();
|
||||
|
@@ -17,12 +17,10 @@ use Chill\PersonBundle\Entity\Relationships\Relation;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use function array_rand;
|
||||
use function json_encode;
|
||||
use function random_int;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class RelationshipApiControllerTest extends WebTestCase
|
||||
@@ -63,7 +61,7 @@ final class RelationshipApiControllerTest extends WebTestCase
|
||||
->setParameter('name', 'Center A')
|
||||
->getQuery()
|
||||
->setMaxResults(1)
|
||||
->setFirstResult(random_int(0, $countPersons - 1))
|
||||
->setFirstResult(\random_int(0, $countPersons - 1))
|
||||
->getSingleResult();
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
@@ -96,7 +94,7 @@ final class RelationshipApiControllerTest extends WebTestCase
|
||||
->setParameter('name', 'Center A')
|
||||
->getQuery()
|
||||
->setMaxResults(2)
|
||||
->setFirstResult(random_int(0, $countPersons - 1))
|
||||
->setFirstResult(\random_int(0, $countPersons - 1))
|
||||
->getResult();
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
@@ -132,7 +130,7 @@ final class RelationshipApiControllerTest extends WebTestCase
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
json_encode([
|
||||
\json_encode([
|
||||
'type' => 'relationship',
|
||||
'fromPerson' => ['id' => $fromPersonId, 'type' => 'person'],
|
||||
'toPerson' => ['id' => $toPersonId, 'type' => 'person'],
|
||||
@@ -152,6 +150,6 @@ final class RelationshipApiControllerTest extends WebTestCase
|
||||
->findAll();
|
||||
}
|
||||
|
||||
return $this->relations[array_rand($this->relations)];
|
||||
return $this->relations[\array_rand($this->relations)];
|
||||
}
|
||||
}
|
||||
|
@@ -14,12 +14,10 @@ namespace Chill\PersonBundle\Tests\Controller;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use function array_pop;
|
||||
use function count;
|
||||
use function json_decode;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class SocialIssueApiControllerTest extends WebTestCase
|
||||
@@ -38,14 +36,14 @@ final class SocialIssueApiControllerTest extends WebTestCase
|
||||
{
|
||||
$socialIssues = $data['results'];
|
||||
shuffle($socialIssues);
|
||||
$socialIssue = array_pop($socialIssues);
|
||||
$socialIssue = \array_pop($socialIssues);
|
||||
|
||||
$client = $this->getClientAuthenticated();
|
||||
$client->request(Request::METHOD_GET, sprintf('/api/1.0/person/social-work/social-issue/%d.json', $socialIssue['id']));
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$data = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertArrayHasKey('type', $data);
|
||||
@@ -58,10 +56,10 @@ final class SocialIssueApiControllerTest extends WebTestCase
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$data = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
$data = \json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->assertGreaterThan(0, $data['count']);
|
||||
$this->assertGreaterThan(0, count($data['results']));
|
||||
$this->assertGreaterThan(0, \count($data['results']));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class SocialWorkEvaluationApiControllerTest extends WebTestCase
|
||||
@@ -52,7 +53,7 @@ final class SocialWorkEvaluationApiControllerTest extends WebTestCase
|
||||
|
||||
/** @var SocialAction $socialAction */
|
||||
$socialAction = $this->em->createQuery(
|
||||
'SELECT s FROM ' . SocialAction::class . ' s WHERE SIZE(s.evaluations) >= 2'
|
||||
'SELECT s FROM '.SocialAction::class.' s WHERE SIZE(s.evaluations) >= 2'
|
||||
)
|
||||
->setMaxResults(1)
|
||||
->getSingleResult();
|
||||
|
Reference in New Issue
Block a user