From 2c52a5bffa0d12c159d45e36ad929758ac66dff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 1 Sep 2023 16:10:04 +0200 Subject: [PATCH] Fix tests --- .../Test/Export/AbstractAggregatorTest.php | 6 ++++++ .../AddressToReferenceMatcherControllerTest.php | 7 ++----- .../Resolver/DefaultScopeResolverTest.php | 2 +- .../Export/Export/ListPerson.php | 3 ++- .../Controller/PersonControllerCreateTest.php | 1 - .../Controller/RelationshipApiControllerTest.php | 3 +-- .../Export/CountAccompanyingPeriodWorkTest.php | 2 +- .../Tests/Export/Export/CountPersonTest.php | 3 ++- .../Tests/Export/Export/ListPersonTest.php | 16 +++++++--------- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php index e8917b064..faaa4a560 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractAggregatorTest.php @@ -27,6 +27,12 @@ use function is_string; */ abstract class AbstractAggregatorTest extends KernelTestCase { + + public static function tearDownAfterClass(): void + { + self::ensureKernelShutdown(); + } + /** * provide data for `testAliasDidNotDisappears`. */ diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/AddressToReferenceMatcherControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/AddressToReferenceMatcherControllerTest.php index aa64d1539..87ae93e26 100644 --- a/src/Bundle/ChillMainBundle/Tests/Controller/AddressToReferenceMatcherControllerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Controller/AddressToReferenceMatcherControllerTest.php @@ -29,11 +29,6 @@ class AddressToReferenceMatcherControllerTest extends WebTestCase private AddressRepository $addressRepository; - protected function setUp(): void - { - $this->addressRepository = self::$container->get(AddressRepository::class); - } - protected function tearDown(): void { self::ensureKernelShutdown(); @@ -50,6 +45,7 @@ class AddressToReferenceMatcherControllerTest extends WebTestCase $this->assertResponseIsSuccessful(); + $this->addressRepository = self::$container->get(AddressRepository::class); $address = $this->addressRepository->find($addressId); $this->assertEquals(Address::ADDR_REFERENCE_STATUS_REVIEWED, $address->getRefStatus()); @@ -66,6 +62,7 @@ class AddressToReferenceMatcherControllerTest extends WebTestCase $this->assertResponseIsSuccessful(); + $this->addressRepository = self::$container->get(AddressRepository::class); $address = $this->addressRepository->find($addressId); $this->assertEquals(Address::ADDR_REFERENCE_STATUS_MATCH, $address->getRefStatus()); diff --git a/src/Bundle/ChillMainBundle/Tests/Security/Resolver/DefaultScopeResolverTest.php b/src/Bundle/ChillMainBundle/Tests/Security/Resolver/DefaultScopeResolverTest.php index 037a7272b..72095a48c 100644 --- a/src/Bundle/ChillMainBundle/Tests/Security/Resolver/DefaultScopeResolverTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Security/Resolver/DefaultScopeResolverTest.php @@ -58,7 +58,7 @@ final class DefaultScopeResolverTest extends TestCase public function getScopes(): iterable { - return $this->scopes; + return [$this->scopeA, $this->scopeB]; } }; diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php index 1274780f7..9f700c697 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php @@ -50,7 +50,8 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou { private array $slugs = []; - public function __construct(private readonly ExportAddressHelper $addressHelper, private readonly CustomFieldProvider $customFieldProvider, private readonly ListPersonHelper $listPersonHelper, private readonly EntityManagerInterface $entityManager, private readonly TranslatableStringHelper $translatableStringHelper) + public function __construct( + private readonly ExportAddressHelper $addressHelper, private readonly CustomFieldProvider $customFieldProvider, private readonly ListPersonHelper $listPersonHelper, private readonly EntityManagerInterface $entityManager, private readonly TranslatableStringHelper $translatableStringHelper) { } diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php index 57bb7ac21..4f5a57d14 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php @@ -180,7 +180,6 @@ final class PersonControllerCreateTest extends WebTestCase $form = $crawler->selectButton("Créer l'usager")->form(); $this->fillAValidCreationForm($form, uniqid(), uniqid()); - $client = $this->client; $client->submit($form); self::assertResponseRedirects(); diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php index b97e4a6e8..5bcfd3967 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php @@ -15,7 +15,6 @@ use Chill\MainBundle\Test\PrepareClientTrait; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Relationships\Relation; use Doctrine\ORM\EntityManagerInterface; -use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\HttpFoundation\Request; use function array_rand; @@ -116,7 +115,7 @@ final class RelationshipApiControllerTest extends WebTestCase $client = $this->getClientAuthenticated(); $client->request(Request::METHOD_GET, sprintf('/api/1.0/relations/relationship/by-person/%d.json', $personId)); - $response = $this->client->getResponse(); + $response = $client->getResponse(); $this->assertEquals(200, $response->getStatusCode(), 'Test to see that API response returns a status code 200'); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingPeriodWorkTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingPeriodWorkTest.php index a16e04359..3a7ec051b 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingPeriodWorkTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountAccompanyingPeriodWorkTest.php @@ -27,7 +27,7 @@ final class CountAccompanyingPeriodWorkTest extends AbstractExportTest { self::bootKernel(); - $this->export = self::$container->get('chill.person.export.count_social_work_actions'); + $this->export = self::$container->get(CountAccompanyingPeriodWork::class); } public function getExport() diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php index 1b3055b60..74acdfbb0 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Export; use Chill\MainBundle\Test\Export\AbstractExportTest; +use Chill\PersonBundle\Export\Export\CountPerson; /** * Test CountPerson export. @@ -30,7 +31,7 @@ final class CountPersonTest extends AbstractExportTest { self::bootKernel(); - $this->export = self::$container->get('chill.person.export.count_person'); + $this->export = self::$container->get(CountPerson::class); } public function getExport() diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php index 44381cc7d..eefff0bee 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Export\Export; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\PersonBundle\Export\Export\ListPerson; use DateTime; @@ -32,7 +33,7 @@ final class ListPersonTest extends AbstractExportTest { self::bootKernel(); - $this->export = self::$container->get('chill.person.export.list_person'); + $this->export = self::$container->get(ListPerson::class); $request = $this->prophesize() ->willExtend(\Symfony\Component\HttpFoundation\Request::class); @@ -48,20 +49,17 @@ final class ListPersonTest extends AbstractExportTest return $this->export; } - public function getFormData(): array + public function getFormData(): iterable { - return [ + foreach ([ ['fields' => ['id', 'firstName', 'lastName']], ['fields' => ['id', 'birthdate', 'gender', 'memo', 'email', 'phonenumber']], ['fields' => ['firstName', 'lastName', 'phonenumber']], ['fields' => ['id', 'nationality']], ['fields' => ['id', 'countryOfBirth']], - ['fields' => ['id', 'address_street_address_1', - 'address_street_address_2', 'address_valid_from', - 'address_postcode_label', 'address_postcode_code', - 'address_country_name', 'address_country_code', ], - 'address_date' => DateTime::createFromFormat('Y-m-d', '2016-06-12'), ], - ]; + ] as $base) { + yield [...$base, 'address_date' => new \DateTimeImmutable('today') ]; + } } public function getModifiersCombination(): array