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

@@ -32,6 +32,7 @@ use Symfony\Component\Workflow\Registry;
/**
* @internal
*
* @coversNothing
*/
class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
@@ -76,7 +77,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
foreach (self::$periodsIdsToDelete as $id) {
if (null === $period = $repository->find($id)) {
throw new \RuntimeException("period not found while trying to delete it");
throw new \RuntimeException('period not found while trying to delete it');
}
foreach ($period->getParticipations() as $participation) {
@@ -87,7 +88,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
foreach (self::$entitiesToDelete as [$class, $id]) {
if (null === $entity = $em->find($class, $id)) {
throw new \RuntimeException(sprintf("entity %s with id %d not found", $class, $id));
throw new \RuntimeException(sprintf('entity %s with id %d not found', $class, $id));
}
$em->remove($entity);
}
@@ -97,9 +98,10 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
/**
* @dataProvider provideDataFindByUserAndPostalCodesOpenedAccompanyingPeriod
*
* @param list<array{center: Center, scopeOnRole: list<Scope>, scopeCanSeeConfidential: list<Scope>}> $centerScopes
* @param list<AccompanyingPeriod> $expectedContains
* @param list<AccompanyingPeriod> $expectedNotContains
* @param list<AccompanyingPeriod> $expectedContains
* @param list<AccompanyingPeriod> $expectedNotContains
*/
public function testFindByUserAndPostalCodesOpenedAccompanyingPeriod(User $user, User $searched, array $centerScopes, array $expectedContains, array $expectedNotContains, string $message): void
{
@@ -142,22 +144,22 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
{
$this->setUp();
if (null === $user = $this->entityManager->createQuery("SELECT u FROM " . User::class . " u")->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException("no user found");
if (null === $user = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException('no user found');
}
if (null === $anotherUser = $this->entityManager->createQuery("SELECT u FROM " . User::class . " u WHERE u.id != :uid")->setParameter('uid', $user->getId())
if (null === $anotherUser = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u WHERE u.id != :uid')->setParameter('uid', $user->getId())
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException("no user found");
throw new \RuntimeException('no user found');
}
$persons = $this->entityManager
->createQuery("SELECT p FROM " . Person::class . " p JOIN p.centerCurrent current_center")
->createQuery('SELECT p FROM '.Person::class.' p JOIN p.centerCurrent current_center')
->setMaxResults(4)
->getResult();
if (4 > count($persons)) {
throw new \RuntimeException("no person found");
throw new \RuntimeException('no person found');
}
/** @var Person $person */
@@ -166,16 +168,16 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
$scopes = $this->scopeRepository->findAll();
if (3 > count($scopes)) {
throw new \RuntimeException("not enough scopes for this test");
throw new \RuntimeException('not enough scopes for this test');
}
$scopesCanSee = [ $scopes[0] ];
$scopesGroup2 = [ $scopes[1] ];
$scopesCanSee = [$scopes[0]];
$scopesGroup2 = [$scopes[1]];
$centers = $this->centerRepository->findActive();
$aCenterNotAssociatedToPerson = array_values(array_filter($centers, fn (Center $c) => $c !== $person->getCenter()))[0];
if (2 > count($centers)) {
throw new \RuntimeException("not enough centers for this test");
throw new \RuntimeException('not enough centers for this test');
}
$period = $this->buildPeriod($person, $scopesCanSee, $user, true);
@@ -193,7 +195,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
],
[$period],
[],
"period should be visible with expected scopes",
'period should be visible with expected scopes',
];
yield [
@@ -208,10 +210,10 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
],
[],
[$period],
"period should not be visible without expected scopes",
'period should not be visible without expected scopes',
];
yield [
yield [
$anotherUser,
$user,
[
@@ -228,7 +230,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
],
[],
[$period],
"period should not be visible for user having right in another scope (with multiple centers)"
'period should not be visible for user having right in another scope (with multiple centers)',
];
$period = $this->buildPeriod($person, $scopesCanSee, $user, true);
@@ -247,7 +249,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
],
[],
[$period],
"period confidential should not be visible",
'period confidential should not be visible',
];
yield [
@@ -262,7 +264,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
],
[$period],
[],
"period confidential be visible if user has required scopes",
'period confidential be visible if user has required scopes',
];
$this->entityManager->flush();
@@ -270,9 +272,10 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
/**
* @dataProvider provideDataFindByUndispatched
*
* @param list<array{center: Center, scopeOnRole: list<Scope>, scopeCanSeeConfidential: list<Scope>}> $centerScopes
* @param list<AccompanyingPeriod> $expectedContains
* @param list<AccompanyingPeriod> $expectedNotContains
* @param list<AccompanyingPeriod> $expectedContains
* @param list<AccompanyingPeriod> $expectedNotContains
*/
public function testFindByUndispatched(User $user, array $centerScopes, array $expectedContains, array $expectedNotContains, string $message): void
{
@@ -315,23 +318,23 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
{
$this->setUp();
if (null === $user = $this->entityManager->createQuery("SELECT u FROM " . User::class . " u")->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException("no user found");
if (null === $user = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException('no user found');
}
if (null === $anotherUser = $this->entityManager->createQuery("SELECT u FROM " . User::class . " u WHERE u.id != :uid")->setParameter('uid', $user->getId())
if (null === $anotherUser = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u WHERE u.id != :uid')->setParameter('uid', $user->getId())
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException("no user found");
throw new \RuntimeException('no user found');
}
/** @var Person $person */
$persons = $this->entityManager
->createQuery("SELECT p FROM " . Person::class . " p ")
->createQuery('SELECT p FROM '.Person::class.' p ')
->setMaxResults(4)
->getResult();
if (4 > count($persons)) {
throw new \RuntimeException("no person found");
throw new \RuntimeException('no person found');
}
[$person, $anotherPerson, $person2, $person3] = $persons;
@@ -339,20 +342,19 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
$scopes = $this->scopeRepository->findAll();
if (3 > count($scopes)) {
throw new \RuntimeException("not enough scopes for this test");
throw new \RuntimeException('not enough scopes for this test');
}
$scopesCanSee = [ $scopes[0] ];
$scopesGroup2 = [ $scopes[1] ];
$scopesCanSee = [$scopes[0]];
$scopesGroup2 = [$scopes[1]];
$centers = $this->centerRepository->findActive();
if (2 > count($centers)) {
throw new \RuntimeException("not enough centers for this test");
throw new \RuntimeException('not enough centers for this test');
}
$period = $this->buildPeriod($person, $scopesCanSee, $user, true);
// expected scope: can see the period
yield [
$anotherUser,
@@ -365,7 +367,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
],
[$period],
[],
"period should be visible with expected scopes",
'period should be visible with expected scopes',
];
// no scope visible
@@ -380,11 +382,11 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
],
[],
[$period],
"period should not be visible without expected scopes",
'period should not be visible without expected scopes',
];
// another center
yield [
yield [
$anotherUser,
[
[
@@ -400,7 +402,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
],
[],
[$period],
"period should not be visible for user having right in another scope (with multiple centers)"
'period should not be visible for user having right in another scope (with multiple centers)',
];
$this->entityManager->flush();
@@ -410,9 +412,10 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
* For testing this method, we mock the authorization helper to return different Scope that a user
* can see, or that a user can see confidential periods.
*
* @param array<Scope> $scopeUserCanSee
* @param array<Scope> $scopeUserCanSeeConfidential
* @param array<Scope> $scopeUserCanSee
* @param array<Scope> $scopeUserCanSeeConfidential
* @param array<AccompanyingPeriod> $expectedPeriod
*
* @dataProvider provideDataForFindByPerson
*/
public function testFindByPersonTestUser(User $user, Person $person, array $scopeUserCanSee, array $scopeUserCanSeeConfidential, array $expectedPeriod, string $message): void
@@ -446,18 +449,18 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
{
$this->setUp();
if (null === $user = $this->entityManager->createQuery("SELECT u FROM " . User::class . " u")->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException("no user found");
if (null === $user = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException('no user found');
}
if (null === $anotherUser = $this->entityManager->createQuery("SELECT u FROM " . User::class . " u WHERE u.id != :uid")->setParameter('uid', $user->getId())
if (null === $anotherUser = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u WHERE u.id != :uid')->setParameter('uid', $user->getId())
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException("no user found");
throw new \RuntimeException('no user found');
}
if (null === $centerA = $this->entityManager->createQuery("SELECT c FROM " . Center::class . " c WHERE c.name LIKE :cn")->setParameter('cn', 'Center A')
if (null === $centerA = $this->entityManager->createQuery('SELECT c FROM '.Center::class.' c WHERE c.name LIKE :cn')->setParameter('cn', 'Center A')
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException("Center A not found");
throw new \RuntimeException('Center A not found');
}
$persons = [new Person(), new Person(), new Person(), new Person()];
$firstnames = ['alpha', 'beta', 'gamma', 'delta'];
@@ -467,7 +470,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
$p
->setFirstName($firstnames[$k])
->setLastName($lastnames[$k])
->setBirthdate((new \DateTime('today'))->sub(new \DateInterval('P' . random_int(18, 100) . 'Y')))
->setBirthdate((new \DateTime('today'))->sub(new \DateInterval('P'.random_int(18, 100).'Y')))
->setCenter($centerA)
;
$this->entityManager->persist($p);
@@ -479,39 +482,39 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
$scopes = $this->scopeRepository->findAll();
if (3 > count($scopes)) {
throw new \RuntimeException("not enough scopes for this test");
throw new \RuntimeException('not enough scopes for this test');
}
$scopesCanSee = [ $scopes[0] ];
$scopesGroup2 = [ $scopes[1] ];
$scopesCanSee = [$scopes[0]];
$scopesGroup2 = [$scopes[1]];
// case: a period is in draft state
$period = $this->buildPeriod($person, $scopesCanSee, $user, false);
yield [$user, $person, $scopesCanSee, [], [$period], "a user can see his period during draft state"];
yield [$user, $person, $scopesCanSee, [], [$period], 'a user can see his period during draft state'];
// another user is not allowed to see this period, because it is in DRAFT state
yield [$anotherUser, $person, $scopesCanSee, [], [], "another user is not allowed to see the period of someone else in draft state"];
yield [$anotherUser, $person, $scopesCanSee, [], [], 'another user is not allowed to see the period of someone else in draft state'];
// the period is confirmed
$period = $this->buildPeriod($anotherPerson, $scopesCanSee, $user, true);
// the other user can now see it
yield [$user, $anotherPerson, $scopesCanSee, [], [$period], "a user see his period when confirmed"];
yield [$anotherUser, $anotherPerson, $scopesCanSee, [], [$period], "another user with required scopes is allowed to see the period when not draft"];
yield [$anotherUser, $anotherPerson, $scopesGroup2, [], [], "another user without the required scopes is not allowed to see the period when not draft"];
yield [$user, $anotherPerson, $scopesCanSee, [], [$period], 'a user see his period when confirmed'];
yield [$anotherUser, $anotherPerson, $scopesCanSee, [], [$period], 'another user with required scopes is allowed to see the period when not draft'];
yield [$anotherUser, $anotherPerson, $scopesGroup2, [], [], 'another user without the required scopes is not allowed to see the period when not draft'];
// this period will be confidential
$period = $this->buildPeriod($person2, $scopesCanSee, $user, true);
$period->setConfidential(true)->setUser($user, true);
yield [$user, $person2, $scopesCanSee, [], [$period], "a user see his period when confirmed and confidential with required scopes"];
yield [$user, $person2, $scopesGroup2, [], [$period], "a user see his period when confirmed and confidential without required scopes"];
yield [$user, $person2, $scopesCanSee, [], [$period], 'a user see his period when confirmed and confidential with required scopes'];
yield [$user, $person2, $scopesGroup2, [], [$period], 'a user see his period when confirmed and confidential without required scopes'];
yield [$anotherUser, $person2, $scopesCanSee, [], [], "a user don't see a confidential period, even if he has required scopes"];
yield [$anotherUser, $person2, $scopesCanSee, $scopesCanSee, [$period], "a user see the period when confirmed and confidential if he has required scope to see the period"];
yield [$anotherUser, $person2, $scopesCanSee, $scopesCanSee, [$period], 'a user see the period when confirmed and confidential if he has required scope to see the period'];
// period draft with creator = null
$period = $this->buildPeriod($person3, $scopesCanSee, null, false);
yield [$user, $person3, $scopesCanSee, [], [$period], "a user see a period when draft if no creator on the period"];
yield [$user, $person3, $scopesCanSee, [], [$period], 'a user see a period when draft if no creator on the period'];
$this->entityManager->flush();
}

View File

@@ -23,10 +23,10 @@ use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Security\Core\Security;
use function count;
/**
* @internal
*
* @coversNothing
*/
final class PersonACLAwareRepositoryTest extends KernelTestCase
@@ -91,11 +91,11 @@ final class PersonACLAwareRepositoryTest extends KernelTestCase
$results = $repository->findBySearchCriteria(0, 5, false, 'diallo');
$this->assertGreaterThan(0, count($results));
$this->assertGreaterThan(0, \count($results));
$this->assertContainsOnlyInstancesOf(Person::class, $results);
foreach ($results as $person) {
$this->assertStringContainsString('diallo', strtolower($person->getFirstName() . ' ' . $person->getLastName()));
$this->assertStringContainsString('diallo', strtolower($person->getFirstName().' '.$person->getLastName()));
}
}
}

View File

@@ -16,6 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
*
* @coversNothing
*/
class UserRepositoryTest extends KernelTestCase
@@ -37,7 +38,7 @@ class UserRepositoryTest extends KernelTestCase
$i = 0;
foreach ($userIterator as $u) {
self::assertIsArray($u);
$i++;
++$i;
}
self::assertGreaterThan(0, $i);
}