From 6f11dffcbd12288156f56363178758067abd1635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 31 Aug 2023 18:36:37 +0200 Subject: [PATCH] Remove deprecation linked to kernel shutdown --- .../AsideActivityControllerTest.php | 7 +++- .../Controller/CalendarControllerTest.php | 19 +++++++--- ...emoteCalendarMSGraphSyncControllerTest.php | 4 +- .../PersonDocumentGenericDocProviderTest.php | 2 +- .../Controller/EventController.php | 2 +- .../Controller/AddressControllerTest.php | 10 +++-- ...ddressToReferenceMatcherControllerTest.php | 10 ++++- .../PermissionApiControllerTest.php | 7 ++++ .../Tests/Controller/UserControllerTest.php | 5 ++- .../Resolver/DefaultScopeResolverTest.php | 6 +-- .../Resolver/ScopeResolverDispatcherTest.php | 7 +++- .../AccompanyingPeriodConfidentialTest.php | 22 +++++------ .../AccompanyingCourseApiControllerTest.php | 38 +++++++++++-------- .../AccompanyingCourseControllerTest.php | 12 +++++- ...yingPeriodRegulationListControllerTest.php | 8 +--- .../Controller/HouseholdApiControllerTest.php | 9 +++++ .../Controller/HouseholdControllerTest.php | 7 ++++ .../Controller/PersonControllerCreateTest.php | 14 ++++--- .../Controller/PersonControllerUpdateTest.php | 9 ++++- .../Controller/PersonControllerViewTest.php | 6 ++- .../RelationshipApiControllerTest.php | 20 ++++++---- .../SocialIssueApiControllerTest.php | 6 +-- .../Tests/Search/PersonSearchTest.php | 21 +++++++--- 23 files changed, 166 insertions(+), 85 deletions(-) diff --git a/src/Bundle/ChillAsideActivityBundle/src/Tests/Controller/AsideActivityControllerTest.php b/src/Bundle/ChillAsideActivityBundle/src/Tests/Controller/AsideActivityControllerTest.php index 196dd5bc3..f2ca7b7cb 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Tests/Controller/AsideActivityControllerTest.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Tests/Controller/AsideActivityControllerTest.php @@ -14,6 +14,7 @@ namespace Chill\AsideActivityBundle\Tests\Controller; use Chill\AsideActivityBundle\Entity\AsideActivity; use Chill\MainBundle\Test\PrepareClientTrait; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use function array_pop; use function shuffle; @@ -26,10 +27,10 @@ final class AsideActivityControllerTest extends WebTestCase { use PrepareClientTrait; + private KernelBrowser $client; + protected function setUp(): void { - parent::setUp(); - self::bootKernel(); $this->client = $this->getClientAuthenticated(); } @@ -57,6 +58,8 @@ final class AsideActivityControllerTest extends WebTestCase yield [array_pop($asideActivityIds)['id']]; yield [array_pop($asideActivityIds)['id']]; + + self::ensureKernelShutdown(); } /** diff --git a/src/Bundle/ChillCalendarBundle/Tests/Controller/CalendarControllerTest.php b/src/Bundle/ChillCalendarBundle/Tests/Controller/CalendarControllerTest.php index 6d6d53b0a..ba9fecb65 100644 --- a/src/Bundle/ChillCalendarBundle/Tests/Controller/CalendarControllerTest.php +++ b/src/Bundle/ChillCalendarBundle/Tests/Controller/CalendarControllerTest.php @@ -11,9 +11,11 @@ declare(strict_types=1); namespace Chill\CalendarBundle\Tests\Controller; +use Chill\MainBundle\Test\PrepareClientTrait; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\HttpFoundation\Request; use function random_int; @@ -24,16 +26,21 @@ use function random_int; */ final class CalendarControllerTest extends WebTestCase { + use PrepareClientTrait; + + private KernelBrowser $client; + /** * Setup before each test method (see phpunit doc). */ protected function setUp(): void { - self::bootKernel(); - $this->client = self::createClient([], [ - 'PHP_AUTH_USER' => 'center a_social', - 'PHP_AUTH_PW' => 'password', - ]); + $this->client = $this->getClientAuthenticated(); + } + + protected function tearDown(): void + { + self::ensureKernelShutdown(); } public function provideAccompanyingPeriod(): iterable @@ -73,6 +80,8 @@ final class CalendarControllerTest extends WebTestCase ->getQuery() ->getSingleScalarResult(), ]; + + self::ensureKernelShutdown(); } /** diff --git a/src/Bundle/ChillCalendarBundle/Tests/Controller/RemoteCalendarMSGraphSyncControllerTest.php b/src/Bundle/ChillCalendarBundle/Tests/Controller/RemoteCalendarMSGraphSyncControllerTest.php index e805f71aa..1d4fb46b1 100644 --- a/src/Bundle/ChillCalendarBundle/Tests/Controller/RemoteCalendarMSGraphSyncControllerTest.php +++ b/src/Bundle/ChillCalendarBundle/Tests/Controller/RemoteCalendarMSGraphSyncControllerTest.php @@ -48,9 +48,9 @@ final class RemoteCalendarMSGraphSyncControllerTest extends WebTestCase } JSON; - protected function setUp(): void + protected function tearDown(): void { - self::bootKernel(); + self::ensureKernelShutdown(); } public function testSendNotification(): void diff --git a/src/Bundle/ChillDocStoreBundle/Tests/GenericDoc/Providers/PersonDocumentGenericDocProviderTest.php b/src/Bundle/ChillDocStoreBundle/Tests/GenericDoc/Providers/PersonDocumentGenericDocProviderTest.php index 577357820..dada613b5 100644 --- a/src/Bundle/ChillDocStoreBundle/Tests/GenericDoc/Providers/PersonDocumentGenericDocProviderTest.php +++ b/src/Bundle/ChillDocStoreBundle/Tests/GenericDoc/Providers/PersonDocumentGenericDocProviderTest.php @@ -67,7 +67,7 @@ class PersonDocumentGenericDocProviderTest extends KernelTestCase ['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query); $nb = $this->entityManager->getConnection() - ->fetchOne("SELECT COUNT(*) AS nb FROM (${sql}) AS sq", $params, $types); + ->fetchOne("SELECT COUNT(*) AS nb FROM ({$sql}) AS sq", $params, $types); self::assertIsInt($nb, "Test that the query is syntactically correct"); } diff --git a/src/Bundle/ChillEventBundle/Controller/EventController.php b/src/Bundle/ChillEventBundle/Controller/EventController.php index 23f2883ee..14ff0d560 100644 --- a/src/Bundle/ChillEventBundle/Controller/EventController.php +++ b/src/Bundle/ChillEventBundle/Controller/EventController.php @@ -279,7 +279,7 @@ class EventController extends AbstractController /** * @var Center $centers */ - $centers = $this->authorizationHelper->getReachableCenters($this->getUser(), (string) $role); + $centers = $this->authorizationHelper->getReachableCenters($this->getUser(), $role); if (count($centers) === 1) { return $this->redirectToRoute('chill_event__event_new', [ diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/AddressControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/AddressControllerTest.php index e0d781a18..cfe99c32c 100644 --- a/src/Bundle/ChillMainBundle/Tests/Controller/AddressControllerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Controller/AddressControllerTest.php @@ -26,13 +26,12 @@ final class AddressControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\W private KernelBrowser $client; - protected function setUp(): void + protected function tearDown(): void { - self::bootKernel(); - $this->client = $this->getClientAuthenticated(); + self::ensureKernelShutdown(); } - public function generateAddressIds() + public function generateAddressIds(): iterable { self::bootKernel(); $em = self::$container->get(EntityManagerInterface::class); @@ -46,6 +45,8 @@ final class AddressControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\W foreach ($addresses as $a) { yield [$a->getId()]; } + + self::ensureKernelShutdown(); } /** @@ -53,6 +54,7 @@ final class AddressControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\W */ public function testDuplicate(int $addressId) { + $this->client = $this->getClientAuthenticated(); $this->client->request('POST', "/api/1.0/main/address/{$addressId}/duplicate.json"); $this->assertResponseIsSuccessful('test that duplicate is successful'); diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/AddressToReferenceMatcherControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/AddressToReferenceMatcherControllerTest.php index dfc713f7f..aa64d1539 100644 --- a/src/Bundle/ChillMainBundle/Tests/Controller/AddressToReferenceMatcherControllerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Controller/AddressToReferenceMatcherControllerTest.php @@ -31,10 +31,14 @@ class AddressToReferenceMatcherControllerTest extends WebTestCase protected function setUp(): void { - self::bootKernel(); $this->addressRepository = self::$container->get(AddressRepository::class); } + protected function tearDown(): void + { + self::ensureKernelShutdown(); + } + /** * @dataProvider addressToReviewProvider */ @@ -92,6 +96,8 @@ class AddressToReferenceMatcherControllerTest extends WebTestCase $em->flush(); yield [$address->getId()]; + + self::ensureKernelShutdown(); } public static function addressUnsyncedProvider(): iterable @@ -123,5 +129,7 @@ class AddressToReferenceMatcherControllerTest extends WebTestCase $em->flush(); yield [$address->getId()]; + + self::ensureKernelShutdown(); } } diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/PermissionApiControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/PermissionApiControllerTest.php index 2b89ec3db..75fdbf2e6 100644 --- a/src/Bundle/ChillMainBundle/Tests/Controller/PermissionApiControllerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Controller/PermissionApiControllerTest.php @@ -23,8 +23,15 @@ final class PermissionApiControllerTest extends WebTestCase { use PrepareClientTrait; + protected function tearDown(): void + { + self::ensureKernelShutdown(); + } + public function testDenormalizingObject() { + // for a unknown reason, the kernel may be booted before running this test... + self::ensureKernelShutdown(); $client = $this->getClientAuthenticated(); $client->request( diff --git a/src/Bundle/ChillMainBundle/Tests/Controller/UserControllerTest.php b/src/Bundle/ChillMainBundle/Tests/Controller/UserControllerTest.php index 843cc3022..64524d86d 100644 --- a/src/Bundle/ChillMainBundle/Tests/Controller/UserControllerTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Controller/UserControllerTest.php @@ -29,8 +29,6 @@ final class UserControllerTest extends WebTestCase protected function setUp(): void { - self::bootKernel(); - $this->client = self::createClient([], [ 'PHP_AUTH_USER' => 'admin', 'PHP_AUTH_PW' => 'password', @@ -49,6 +47,7 @@ final class UserControllerTest extends WebTestCase } $em->flush(); + self::ensureKernelShutdown(); } public function dataGenerateUserId() @@ -69,6 +68,8 @@ final class UserControllerTest extends WebTestCase $this->toDelete[] = [User::class, $user->getId()]; yield [$user->getId(), $user->getUsername()]; + + self::ensureKernelShutdown(); } public function testList() diff --git a/src/Bundle/ChillMainBundle/Tests/Security/Resolver/DefaultScopeResolverTest.php b/src/Bundle/ChillMainBundle/Tests/Security/Resolver/DefaultScopeResolverTest.php index 30d50fca5..e28558a20 100644 --- a/src/Bundle/ChillMainBundle/Tests/Security/Resolver/DefaultScopeResolverTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Security/Resolver/DefaultScopeResolverTest.php @@ -34,9 +34,8 @@ final class DefaultScopeResolverTest extends TestCase { $scope = new Scope(); $entity = new class ($scope) implements HasScopeInterface { - public function __construct(Scope $scope) + public function __construct(private readonly Scope $scope) { - $this->scope = $scope; } public function getScope() @@ -53,9 +52,8 @@ final class DefaultScopeResolverTest extends TestCase public function testHasScopesInterface() { $entity = new class ($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface { - public function __construct(Scope $scopeA, Scope $scopeB) + public function __construct(private Scope $scopeA, private Scope $scopeB) { - $this->scopes = [$scopeA, $scopeB]; } public function getScopes(): iterable diff --git a/src/Bundle/ChillMainBundle/Tests/Security/Resolver/ScopeResolverDispatcherTest.php b/src/Bundle/ChillMainBundle/Tests/Security/Resolver/ScopeResolverDispatcherTest.php index 31e5229bb..6a6b798d5 100644 --- a/src/Bundle/ChillMainBundle/Tests/Security/Resolver/ScopeResolverDispatcherTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Security/Resolver/ScopeResolverDispatcherTest.php @@ -35,9 +35,8 @@ final class ScopeResolverDispatcherTest extends TestCase { $scope = new Scope(); $entity = new class ($scope) implements HasScopeInterface { - public function __construct(Scope $scope) + public function __construct(private readonly Scope $scope) { - $this->scope = $scope; } public function getScope() @@ -53,6 +52,10 @@ final class ScopeResolverDispatcherTest extends TestCase public function testHasScopesInterface() { $entity = new class ($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface { + /** + * @var Scope[] + */ + private array $scopes = []; public function __construct(Scope $scopeA, Scope $scopeB) { $this->scopes = [$scopeA, $scopeB]; diff --git a/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/AccompanyingPeriodConfidentialTest.php b/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/AccompanyingPeriodConfidentialTest.php index 0dd689d6d..c12683967 100644 --- a/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/AccompanyingPeriodConfidentialTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/AccompanyingPeriod/AccompanyingPeriodConfidentialTest.php @@ -12,7 +12,9 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\AccompanyingPeriod; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Test\PrepareClientTrait; use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; /** @@ -21,23 +23,21 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; */ final class AccompanyingPeriodConfidentialTest extends WebTestCase { - /** - * Setup before the first test of this class (see phpunit doc). - */ - public static function setUpBeforeClass(): void - { - self::bootKernel(); - } + use PrepareClientTrait; + + private KernelBrowser $client; /** * Setup before each test method (see phpunit doc). */ protected function setUp(): void { - $this->client = self::createClient([], [ - 'PHP_AUTH_USER' => 'fred', - 'PHP_AUTH_PW' => 'password', - ]); + $this->client = $this->getClientAuthenticated(); + } + + protected function tearDown(): void + { + self::ensureKernelShutdown(); } /** diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php index 574c8cc64..64b78f49e 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseApiControllerTest.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Tests\Controller; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Test\PrepareClientTrait; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\PersonBundle\Entity\Person; @@ -22,6 +23,7 @@ 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; @@ -40,31 +42,29 @@ use function json_encode; */ final class AccompanyingCourseApiControllerTest extends WebTestCase { - protected static EntityManagerInterface $em; + use PrepareClientTrait; - protected ?AccompanyingPeriod $period = null; + private static EntityManagerInterface $em; - protected ?int $periodId = null; + private ?AccompanyingPeriod $period = null; - protected ?int $personId = null; + private ?int $periodId = null; - /** - * Setup before the first test of this class (see phpunit doc). - */ - public static function setUpBeforeClass(): void - { - self::bootKernel(); - } + private ?int $personId = null; + + private KernelBrowser $client; /** * Setup before each test method (see phpunit doc). */ protected function setUp(): void { - $this->client = self::createClient([], [ - 'PHP_AUTH_USER' => 'center a_social', - 'PHP_AUTH_PW' => 'password', - ]); + $this->client = $this->getClientAuthenticated(); + } + + protected function tearDown(): void + { + self::ensureKernelShutdown(); } public function dataGenerateNewAccompanyingCourse() @@ -100,6 +100,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase $em->flush(); yield [$period]; + + self::ensureKernelShutdown(); } public function dataGenerateRandomAccompanyingCourse() @@ -165,6 +167,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase ++$nbGenerated; } + + self::ensureKernelShutdown(); } public function dataGenerateRandomAccompanyingCourseWithSocialIssue() @@ -235,6 +239,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase ++$nbGenerated; } + + self::ensureKernelShutdown(); } public function dataGenerateRandomRequestorValidData(): Iterator @@ -302,6 +308,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase yield [$period, array_pop($personIds)['id'], array_pop($thirdPartyIds)['id']]; ++$i; } + + self::ensureKernelShutdown(); } /** diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseControllerTest.php index c5e98caa5..35d276c7c 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingCourseControllerTest.php @@ -19,6 +19,7 @@ use Chill\PersonBundle\Entity\Person; use DateTime; use Doctrine\ORM\EntityManagerInterface; use Iterator; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use function array_pop; use function count; @@ -32,13 +33,18 @@ final class AccompanyingCourseControllerTest extends WebTestCase { use PrepareClientTrait; + private KernelBrowser $client; + protected function setUp(): void { - parent::setUp(); - self::bootKernel(); $this->client = $this->getClientAuthenticated(); } + protected function tearDown(): void + { + self::ensureKernelShutdown(); + } + public function dataGenerateRandomUsers(): Iterator { self::bootKernel(); @@ -61,6 +67,8 @@ final class AccompanyingCourseControllerTest extends WebTestCase ->getScalarResult(); yield [array_pop($personIds), array_pop($personIds)]; + + self::ensureKernelShutdown(); } public function testNewWithoutUsers() diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodRegulationListControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodRegulationListControllerTest.php index 80f755d9c..80b73673b 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodRegulationListControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodRegulationListControllerTest.php @@ -22,12 +22,6 @@ final class AccompanyingPeriodRegulationListControllerTest extends WebTestCase { use PrepareClientTrait; - protected function setUp(): void - { - parent::setUp(); - self::bootKernel(); - } - public function testRegulationList(): void { $client = $this->getClientAuthenticated(); @@ -35,5 +29,7 @@ final class AccompanyingPeriodRegulationListControllerTest extends WebTestCase $client->request('GET', '/fr/person/periods/undispatched'); $this->assertResponseIsSuccessful(); + + self::ensureKernelShutdown(); } } diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdApiControllerTest.php index 365904f0d..2e1c58c64 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdApiControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdApiControllerTest.php @@ -42,6 +42,7 @@ final class HouseholdApiControllerTest extends WebTestCase protected function tearDown(): void { self::bootKernel(); + $em = self::$container->get(EntityManagerInterface::class); foreach ($this->toDelete as [$class, $id]) { @@ -50,6 +51,8 @@ final class HouseholdApiControllerTest extends WebTestCase } $em->flush(); + + self::ensureKernelShutdown(); } public function generateHouseholdAssociatedWithAddressReference() @@ -91,6 +94,8 @@ final class HouseholdApiControllerTest extends WebTestCase ]; yield [$reference->getId(), $h->getId()]; + + self::ensureKernelShutdown(); } public function generateHouseholdId() @@ -121,6 +126,8 @@ final class HouseholdApiControllerTest extends WebTestCase yield [array_pop($householdIds)['id']]; yield [array_pop($householdIds)['id']]; + + self::ensureKernelShutdown(); } public function generatePersonId() @@ -144,6 +151,8 @@ final class HouseholdApiControllerTest extends WebTestCase ->first()->getPerson(); yield [$person->getId()]; + + self::ensureKernelShutdown(); } /** diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdControllerTest.php index 93ec2f4a5..702c4f2b6 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/HouseholdControllerTest.php @@ -37,6 +37,11 @@ final class HouseholdControllerTest extends WebTestCase $this->client = $this->getClientAuthenticated(); } + protected function tearDown(): void + { + self::ensureKernelShutdown(); + } + public function generateValidHouseholdIds() { self::bootKernel(); @@ -60,6 +65,8 @@ final class HouseholdControllerTest extends WebTestCase yield [array_pop($ids)['id']]; yield [array_pop($ids)['id']]; + + self::ensureKernelShutdown(); } /** diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php index 8691838d0..57bb7ac21 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerCreateTest.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Tests\Controller; use Chill\MainBundle\Test\PrepareClientTrait; use DateTime; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\DomCrawler\Form; @@ -48,7 +49,7 @@ final class PersonControllerCreateTest extends WebTestCase public static function tearDownAfterClass(): void { self::bootKernel(); - $em = self::$kernel->getContainer()->get('doctrine.orm.entity_manager'); + $em = self::$container->get(EntityManagerInterface::class); //remove two people created during test $jesus = $em->getRepository(\Chill\PersonBundle\Entity\Person::class) @@ -65,11 +66,12 @@ final class PersonControllerCreateTest extends WebTestCase $em->remove($jesus2); } $em->flush(); + self::ensureKernelShutdown(); } - protected function setUp(): void + protected function tearDown(): void { - $this->client = $this->getClientAuthenticated(); + self::ensureKernelShutdown(); } /** @@ -79,7 +81,7 @@ final class PersonControllerCreateTest extends WebTestCase */ public function testAddAPersonPage() { - $client = $this->client; + $client = $this->getClientAuthenticated(); $crawler = $client->request('GET', '/fr/person/new'); $this->assertTrue( @@ -137,7 +139,7 @@ final class PersonControllerCreateTest extends WebTestCase public function testReviewExistingDetectionInversedLastNameWithFirstName() { $this->markTestSkipped(); - $client = $this->client; + $client = $this->getClientAuthenticated(); $crawler = $client->request('GET', '/fr/person/new'); @@ -173,7 +175,7 @@ final class PersonControllerCreateTest extends WebTestCase */ public function testValidForm() { - $client = $this->client; + $client = $this->getClientAuthenticated(); $crawler = $client->request('GET', '/fr/person/new'); $form = $crawler->selectButton("Créer l'usager")->form(); diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php index c448283ba..ffc68aa76 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateTest.php @@ -46,9 +46,11 @@ final class PersonControllerUpdateTest extends WebTestCase */ protected function setUp(): void { - self::bootKernel(); + } - $this->client = $this->getClientAuthenticated(); + protected function tearDown(): void + { + self::ensureKernelShutdown(); } public static function tearDownAfterClass(): void @@ -68,6 +70,7 @@ final class PersonControllerUpdateTest extends WebTestCase } $em->flush(); + self::ensureKernelShutdown(); } /** @@ -181,6 +184,8 @@ final class PersonControllerUpdateTest extends WebTestCase $em->flush(); yield [$person->getId()]; + + self::ensureKernelShutdown(); } private function makeEditPath(int $personId): string diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerViewTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerViewTest.php index 8f9cfc2f7..ff9e36446 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerViewTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerViewTest.php @@ -30,9 +30,9 @@ final class PersonControllerViewTest extends WebTestCase */ private static array $toDelete = []; - protected function setUp(): void + protected function tearDown(): void { - self::bootKernel(); + self::ensureKernelShutdown(); } public static function tearDownAfterClass(): void @@ -113,6 +113,8 @@ final class PersonControllerViewTest extends WebTestCase $em->flush(); yield [$person->getId()]; + + self::ensureKernelShutdown(); } private function makeViewPath(int $personId): string diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php index 4d45dc725..03660365f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php @@ -30,8 +30,6 @@ final class RelationshipApiControllerTest extends WebTestCase { use PrepareClientTrait; - private KernelBrowser $client; - /** * A cache for all relations. * @@ -39,10 +37,9 @@ final class RelationshipApiControllerTest extends WebTestCase */ private ?array $relations = null; - protected function setUp(): void + protected function tearDown(): void { - self::bootKernel(); - $this->client = $this->getClientAuthenticated(); + self::ensureKernelShutdown(); } public function personProvider(): array @@ -70,6 +67,8 @@ final class RelationshipApiControllerTest extends WebTestCase ->setFirstResult(random_int(0, $countPersons - 1)) ->getSingleResult(); + self::ensureKernelShutdown(); + return [ [$person->getId()], ]; @@ -101,6 +100,8 @@ final class RelationshipApiControllerTest extends WebTestCase ->setFirstResult(random_int(0, $countPersons - 1)) ->getResult(); + self::ensureKernelShutdown(); + return [ [$persons[0]->getId(), $persons[1]->getId(), $this->getRandomRelation($em)->getId(), true], ]; @@ -111,7 +112,8 @@ final class RelationshipApiControllerTest extends WebTestCase */ public function testGetRelationshipByPerson(mixed $personId) { - $this->client->request(Request::METHOD_GET, sprintf('/api/1.0/relations/relationship/by-person/%d.json', $personId)); + $client = $this->getClientAuthenticated(); + $client->request(Request::METHOD_GET, sprintf('/api/1.0/relations/relationship/by-person/%d.json', $personId)); $response = $this->client->getResponse(); $this->assertEquals(200, $response->getStatusCode(), 'Test to see that API response returns a status code 200'); @@ -122,7 +124,9 @@ final class RelationshipApiControllerTest extends WebTestCase */ public function testPostRelationship(mixed $fromPersonId, mixed $toPersonId, mixed $relationId, mixed $isReverse): void { - $this->client->request( + $client = $this->getClientAuthenticated(); + + $client->request( Request::METHOD_POST, '/api/1.0/relations/relationship.json', [], @@ -137,7 +141,7 @@ final class RelationshipApiControllerTest extends WebTestCase ], JSON_THROW_ON_ERROR) ); - $response = $this->client->getResponse(); + $response = $client->getResponse(); $this->assertEquals(200, $response->getStatusCode()); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/SocialIssueApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/SocialIssueApiControllerTest.php index ba19fc56e..6c0a66b34 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/SocialIssueApiControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/SocialIssueApiControllerTest.php @@ -26,11 +26,9 @@ final class SocialIssueApiControllerTest extends WebTestCase { use PrepareClientTrait; - protected function setUp(): void + protected function tearDown(): void { - parent::setUp(); - - self::bootKernel(); + self::ensureKernelShutdown(); } /** diff --git a/src/Bundle/ChillPersonBundle/Tests/Search/PersonSearchTest.php b/src/Bundle/ChillPersonBundle/Tests/Search/PersonSearchTest.php index 6ad6e01fe..2c6dd3871 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Search/PersonSearchTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Search/PersonSearchTest.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Tests\Search; +use Chill\MainBundle\Test\PrepareClientTrait; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; /** @@ -21,6 +22,13 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; */ final class PersonSearchTest extends WebTestCase { + use PrepareClientTrait; + + protected function tearDown(): void + { + self::ensureKernelShutdown(); + } + public function testDefaultAccented(): never { $this->markTestSkipped('skipped until adapted to new fixtures'); @@ -69,6 +77,8 @@ final class PersonSearchTest extends WebTestCase $this->assertMatchesRegularExpression('/MANÇO/', $crawlerSpecial->filter('.list-with-period')->text()); + self::ensureKernelShutdown(); + $crawlerNoSpecial = $this->generateCrawlerForSearch('@person lastname:manco'); $this->assertMatchesRegularExpression('/MANÇO/', $crawlerNoSpecial->filter('.list-with-period')->text()); @@ -95,6 +105,8 @@ final class PersonSearchTest extends WebTestCase $this->assertMatchesRegularExpression('/Gérard/', $crawlerSpecial->filter('.list-with-period')->text()); + self::ensureKernelShutdown(); + $crawlerNoSpecial = $this->generateCrawlerForSearch('@person firstname:Gerard'); $this->assertMatchesRegularExpression('/Gérard/', $crawlerNoSpecial->filter('.list-with-period')->text()); @@ -197,13 +209,15 @@ final class PersonSearchTest extends WebTestCase public function testSearchWithAuthorization() { $crawlerCanSee = $this->generateCrawlerForSearch('Gérard', 'center a_social'); - $crawlerCannotSee = $this->generateCrawlerForSearch('Gérard', 'center b_social'); $this->assertMatchesRegularExpression( '/DEPARDIEU/', $crawlerCanSee->text(), 'center a_social may see "Depardieu" in center a' ); + self::ensureKernelShutdown(); + + $crawlerCannotSee = $this->generateCrawlerForSearch('Gérard', 'center b_social'); $this->assertDoesNotMatchRegularExpression( '/DEPARDIEU/', $crawlerCannotSee->text(), @@ -229,9 +243,6 @@ final class PersonSearchTest extends WebTestCase */ private function getAuthenticatedClient(mixed $username = 'center a_social') { - return self::createClient([], [ - 'PHP_AUTH_USER' => $username, - 'PHP_AUTH_PW' => 'password', - ]); + return $this->getClientAuthenticated($username); } }