apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -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()