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

@@ -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]);