upgrade phpunit: make data provider static

This commit is contained in:
2024-02-14 12:28:14 +01:00
parent d5115b3718
commit f251e6f100
57 changed files with 142 additions and 121 deletions

View File

@@ -41,7 +41,7 @@ class AccompanyingPeriodStepChangeCronjobTest extends TestCase
$this->assertEquals($canRun, $cronJob->canRun($cronJobExecution));
}
public function provideRunTimes(): iterable
public static function provideRunTimes(): iterable
{
// can run, during the night
yield ['2023-01-15T01:00:00+02:00', new \DateTimeImmutable('2023-01-14T00:00:00+02:00'), true];

View File

@@ -120,7 +120,7 @@ class ConflictTest extends WebTestCase
self::assertResponseStatusCodeSame(409);
}
public function generateAccompanyingPeriodWork(): iterable
public static function generateAccompanyingPeriodWork(): iterable
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);

View File

@@ -48,7 +48,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public function dataGenerateNewAccompanyingCourse()
public static function dataGenerateNewAccompanyingCourse()
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
@@ -85,7 +85,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public function dataGenerateRandomAccompanyingCourse()
public static function dataGenerateRandomAccompanyingCourse()
{
// note about max result for person query, and maxGenerated:
//
@@ -152,7 +152,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public function dataGenerateRandomAccompanyingCourseWithSocialIssue()
public static function dataGenerateRandomAccompanyingCourseWithSocialIssue()
{
// note about max result for person query, and maxGenerated:
//
@@ -224,7 +224,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public function dataGenerateRandomRequestorValidData(): \Iterator
public static function dataGenerateRandomRequestorValidData(): \Iterator
{
$dataLength = 2;
$maxResults = 100;

View File

@@ -41,7 +41,7 @@ final class AccompanyingCourseControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public function dataGenerateRandomUsers(): \Iterator
public static function dataGenerateRandomUsers(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);

View File

@@ -92,7 +92,7 @@ final class HouseholdApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public function generateHouseholdId()
public static function generateHouseholdId()
{
self::bootKernel();
@@ -124,7 +124,7 @@ final class HouseholdApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public function generatePersonId()
public static function generatePersonId()
{
self::bootKernel();

View File

@@ -39,7 +39,7 @@ final class HouseholdControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public function generateValidHouseholdIds()
public static function generateValidHouseholdIds()
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);

View File

@@ -30,7 +30,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
{
use PrepareClientTrait;
public function provideValidDataEditMember(): \Iterator
public static function provideValidDataEditMember(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
@@ -48,7 +48,7 @@ final class HouseholdMemberControllerTest extends WebTestCase
yield [\array_pop($membershipIds)['id']];
}
public function provideValidDataMove(): \Iterator
public static function provideValidDataMove(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);

View File

@@ -26,7 +26,7 @@ final class PersonApiControllerTest extends WebTestCase
{
use PrepareClientTrait;
public function dataGetPersonFromCenterA(): \Iterator
public static function dataGetPersonFromCenterA(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);
@@ -49,7 +49,7 @@ final class PersonApiControllerTest extends WebTestCase
yield \array_pop($personIds);
}
public function dataGetPersonFromCenterB(): \Iterator
public static function dataGetPersonFromCenterB(): \Iterator
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);

View File

@@ -188,7 +188,7 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
*
* @return mixed[]
*/
public function validTextFieldsProvider()
public static function validTextFieldsProvider()
{
return [
['firstName', 'random Value', static fn (Person $person) => $person->getFirstName()],

View File

@@ -23,7 +23,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/
final class PersonDuplicateControllerViewTest extends WebTestCase
{
public function providePersonData(): iterable
public static function providePersonData(): iterable
{
self::bootKernel();

View File

@@ -40,7 +40,7 @@ final class RelationshipApiControllerTest extends WebTestCase
self::ensureKernelShutdown();
}
public function personProvider(): array
public static function personProvider(): array
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);

View File

@@ -21,7 +21,7 @@ use PHPUnit\Framework\TestCase;
*/
final class PersonCreateEventTest extends TestCase
{
public function generateAltNames(): iterator
public static function generateAltNames(): iterator
{
yield ['vinCENT', 'VINCENT'];
@@ -32,7 +32,7 @@ final class PersonCreateEventTest extends TestCase
yield ['émile', 'ÉMILE'];
}
public function generateNames(): iterator
public static function generateNames(): iterator
{
yield ['émelie-marie', 'Émelie-Marie', 'lenaerts', 'LENAERTS'];

View File

@@ -38,7 +38,7 @@ final class ActiveOnDateFilterTest extends AbstractFilterTest
return $this->filter;
}
public function getFormData(): array
public static function getFormData(): array
{
return [
[
@@ -47,7 +47,7 @@ final class ActiveOnDateFilterTest extends AbstractFilterTest
];
}
public function getQueryBuilders(): array
public static function getQueryBuilders(): array
{
self::bootKernel();

View File

@@ -90,10 +90,11 @@ final class FilterListAccompanyingPeriodHelperTest extends KernelTestCase
self::assertIsArray($result);
}
public function dataProviderTestAddFilterAccompanyingPeriod(): iterable
public static function dataProviderTestAddFilterAccompanyingPeriod(): iterable
{
self::setUp();
$qb = $this->entityManager->createQueryBuilder();
self::bootKernel();
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$qb = $entityManager->createQueryBuilder();
$qb
->select('acp.id')

View File

@@ -140,20 +140,23 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
}
}
public function provideDataFindByUserAndPostalCodesOpenedAccompanyingPeriod(): iterable
public static function provideDataFindByUserAndPostalCodesOpenedAccompanyingPeriod(): iterable
{
$this->setUp();
self::bootKernel();
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$scopeRepository = self::getContainer()->get(ScopeRepositoryInterface::class);
$centerRepository = self::getContainer()->get(CenterRepositoryInterface::class);
if (null === $user = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')->setMaxResults(1)->getSingleResult()) {
if (null === $user = $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 = $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');
}
$persons = $this->entityManager
$persons = $entityManager
->createQuery('SELECT p FROM '.Person::class.' p JOIN p.centerCurrent current_center')
->setMaxResults(4)
->getResult();
@@ -165,7 +168,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
/** @var Person $person */
[$person, $anotherPerson, $person2, $person3] = $persons;
$scopes = $this->scopeRepository->findAll();
$scopes = $scopeRepository->findAll();
if (3 > count($scopes)) {
throw new \RuntimeException('not enough scopes for this test');
@@ -173,14 +176,14 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
$scopesCanSee = [$scopes[0]];
$scopesGroup2 = [$scopes[1]];
$centers = $this->centerRepository->findActive();
$centers = $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');
}
$period = $this->buildPeriod($person, $scopesCanSee, $user, true);
$period = self::buildPeriod($person, $scopesCanSee, $user, true);
$period->setUser($user);
yield [
@@ -233,7 +236,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
'period should not be visible for user having right in another scope (with multiple centers)',
];
$period = $this->buildPeriod($person, $scopesCanSee, $user, true);
$period = self::buildPeriod($person, $scopesCanSee, $user, true);
$period->setUser($user);
$period->setConfidential(true);
@@ -267,7 +270,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
'period confidential be visible if user has required scopes',
];
$this->entityManager->flush();
$entityManager->flush();
}
/**
@@ -314,21 +317,24 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
}
}
public function provideDataFindByUndispatched(): iterable
public static function provideDataFindByUndispatched(): iterable
{
$this->setUp();
self::bootKernel();
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$scopeRepository = self::getContainer()->get(ScopeRepositoryInterface::class);
$centerRepository = self::getContainer()->get(CenterRepositoryInterface::class);
if (null === $user = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')->setMaxResults(1)->getSingleResult()) {
if (null === $user = $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 = $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');
}
/** @var Person $person */
$persons = $this->entityManager
$persons = $entityManager
->createQuery('SELECT p FROM '.Person::class.' p ')
->setMaxResults(4)
->getResult();
@@ -339,7 +345,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
[$person, $anotherPerson, $person2, $person3] = $persons;
$scopes = $this->scopeRepository->findAll();
$scopes = $scopeRepository->findAll();
if (3 > count($scopes)) {
throw new \RuntimeException('not enough scopes for this test');
@@ -347,13 +353,13 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
$scopesCanSee = [$scopes[0]];
$scopesGroup2 = [$scopes[1]];
$centers = $this->centerRepository->findActive();
$centers = $centerRepository->findActive();
if (2 > count($centers)) {
throw new \RuntimeException('not enough centers for this test');
}
$period = $this->buildPeriod($person, $scopesCanSee, $user, true);
$period = self::buildPeriod($person, $scopesCanSee, $user, true);
// expected scope: can see the period
yield [
@@ -405,7 +411,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
'period should not be visible for user having right in another scope (with multiple centers)',
];
$this->entityManager->flush();
$entityManager->flush();
}
/**
@@ -445,20 +451,22 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
}
}
public function provideDataForFindByPerson(): iterable
public static function provideDataForFindByPerson(): iterable
{
$this->setUp();
self::bootKernel();
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$scopeRepository = self::getContainer()->get(ScopeRepositoryInterface::class);
if (null === $user = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')->setMaxResults(1)->getSingleResult()) {
if (null === $user = $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 = $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');
}
if (null === $centerA = $this->entityManager->createQuery('SELECT c FROM '.Center::class.' c WHERE c.name LIKE :cn')->setParameter('cn', 'Center A')
if (null === $centerA = $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');
}
@@ -473,13 +481,13 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
->setBirthdate((new \DateTime('today'))->sub(new \DateInterval('P'.random_int(18, 100).'Y')))
->setCenter($centerA)
;
$this->entityManager->persist($p);
$entityManager->persist($p);
self::$entitiesToDelete[] = [Person::class, $p->getId()];
}
[$person, $anotherPerson, $person2, $person3] = $persons;
$scopes = $this->scopeRepository->findAll();
$scopes = $scopeRepository->findAll();
if (3 > count($scopes)) {
throw new \RuntimeException('not enough scopes for this test');
@@ -488,7 +496,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
$scopesGroup2 = [$scopes[1]];
// case: a period is in draft state
$period = $this->buildPeriod($person, $scopesCanSee, $user, false);
$period = self::buildPeriod($person, $scopesCanSee, $user, false);
yield [$user, $person, $scopesCanSee, [], [$period], 'a user can see his period during draft state'];
@@ -496,7 +504,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
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);
$period = self::buildPeriod($anotherPerson, $scopesCanSee, $user, true);
// the other user can now see it
yield [$user, $anotherPerson, $scopesCanSee, [], [$period], 'a user see his period when confirmed'];
@@ -504,7 +512,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
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 = self::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'];
@@ -513,16 +521,19 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
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);
$period = self::buildPeriod($person3, $scopesCanSee, null, false);
yield [$user, $person3, $scopesCanSee, [], [$period], 'a user see a period when draft if no creator on the period'];
$this->entityManager->flush();
$entityManager->flush();
}
/**
* @param array<Scope> $scopes
*/
private function buildPeriod(Person $person, array $scopes, User|null $creator, bool $confirm): AccompanyingPeriod
private static function buildPeriod(Person $person, array $scopes, User|null $creator, bool $confirm): AccompanyingPeriod
{
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$registry = self::getContainer()->get(Registry::class);
$period = new AccompanyingPeriod();
$period->addPerson($person);
if (null !== $creator) {
@@ -533,11 +544,11 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
$period->addScope($scope);
}
$this->entityManager->persist($period);
$entityManager->persist($period);
self::$periodsIdsToDelete[] = $period->getId();
if ($confirm) {
$workflow = $this->registry->get($period, 'accompanying_period_lifecycle');
$workflow = $registry->get($period, 'accompanying_period_lifecycle');
$workflow->apply($period, 'confirm');
}

View File

@@ -77,7 +77,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
$this->normalizer = self::getContainer()->get(NormalizerInterface::class);
}
public function dataGeneratorNormalizationNullOrNotNullHaveSameKeys(): iterable
public static function dataGeneratorNormalizationNullOrNotNullHaveSameKeys(): iterable
{
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read']]];
@@ -88,7 +88,7 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
yield [['docgen:expects' => Person::class, 'groups' => ['docgen:read'], 'docgen:person:with-budget' => true]];
}
public function generateData()
public static function generateData()
{
$person = new Person();
$person

View File

@@ -124,7 +124,7 @@ class AccompanyingPeriodContextTest extends KernelTestCase
call_user_func($assertionsOnData, $data);
}
public function provideNormalizedData(): iterable
public static function provideNormalizedData(): iterable
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);

View File

@@ -115,7 +115,7 @@ final class PersonContextTest extends KernelTestCase
call_user_func($assertionsOnData, $data);
}
public function provideNormalizedData(): iterable
public static function provideNormalizedData(): iterable
{
self::bootKernel();
$em = self::getContainer()->get(EntityManagerInterface::class);

View File

@@ -99,11 +99,12 @@ class AccompanyingPeriodCalendarGenericDocProviderTest extends KernelTestCase
self::assertStringContainsStringIgnoringCase('TRUE = FALSE', $sql);
}
public function provideDataForPerson(): iterable
public static function provideDataForPerson(): iterable
{
$this->setUp();
self::bootKernel();
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
if (null === $person = $this->entityManager->createQuery('SELECT p FROM '.Person::class.' p WHERE SIZE(p.accompanyingPeriodParticipations) > 0')
if (null === $person = $entityManager->createQuery('SELECT p FROM '.Person::class.' p WHERE SIZE(p.accompanyingPeriodParticipations) > 0')
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException('There is no person');
}
@@ -116,11 +117,12 @@ class AccompanyingPeriodCalendarGenericDocProviderTest extends KernelTestCase
yield [$person, null, new \DateTimeImmutable('6 month ago'), null];
}
public function provideDataForAccompanyingPeriod(): iterable
public static function provideDataForAccompanyingPeriod(): iterable
{
$this->setUp();
self::bootKernel();
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
if (null === $period = $this->entityManager->createQuery('SELECT p FROM '.AccompanyingPeriod::class.' p ')
if (null === $period = $entityManager->createQuery('SELECT p FROM '.AccompanyingPeriod::class.' p ')
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException('There is no accompanying period');
}

View File

@@ -70,7 +70,7 @@ class AccompanyingPeriodWorkEvaluationGenericDocProviderTest extends KernelTestC
self::assertIsInt($nb, 'Test that there are no errors');
}
public function provideSearchArguments(): iterable
public static function provideSearchArguments(): iterable
{
yield [null, null, null];
yield [new \DateTimeImmutable('1 month ago'), null, null];

View File

@@ -52,11 +52,12 @@ class PersonCalendarGenericDocProviderTest extends KernelTestCase
self::assertIsInt($nb);
}
public function provideDataForPerson(): iterable
public static function provideDataForPerson(): iterable
{
$this->setUp();
self::bootKernel();
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
if (null === $person = $this->entityManager->createQuery('SELECT p FROM '.Person::class.' p ')
if (null === $person = $entityManager->createQuery('SELECT p FROM '.Person::class.' p ')
->setMaxResults(1)->getSingleResult()) {
throw new \RuntimeException('There is no person');
}

View File

@@ -50,7 +50,7 @@ class ClosingMotiveRenderTest extends KernelTestCase
self::assertStringContainsString($expectedContent, $actual);
}
public function provideClosingMotiveWithRenderString(): iterable
public static function provideClosingMotiveWithRenderString(): iterable
{
$closingMotive = (new ClosingMotive())->setName(['fr' => 'Left']);

View File

@@ -28,7 +28,7 @@ final class TimelineAccompanyingPeriodTest extends WebTestCase
{
use PrepareClientTrait;
public function provideDataPersonWithAccompanyingPeriod()
public static function provideDataPersonWithAccompanyingPeriod()
{
self::bootKernel();

View File

@@ -25,7 +25,7 @@ use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
*/
final class MaxHolderValidatorTest extends ConstraintValidatorTestCase
{
public function provideInvalidHousehold()
public static function provideInvalidHousehold()
{
$household = new Household();
$position = (new Position())