Remove deprecation linked to kernel shutdown

This commit is contained in:
Julien Fastré 2023-08-31 18:36:37 +02:00
parent 7c58880139
commit 6f11dffcbd
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
23 changed files with 166 additions and 85 deletions

View File

@ -14,6 +14,7 @@ namespace Chill\AsideActivityBundle\Tests\Controller;
use Chill\AsideActivityBundle\Entity\AsideActivity; use Chill\AsideActivityBundle\Entity\AsideActivity;
use Chill\MainBundle\Test\PrepareClientTrait; use Chill\MainBundle\Test\PrepareClientTrait;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use function array_pop; use function array_pop;
use function shuffle; use function shuffle;
@ -26,10 +27,10 @@ final class AsideActivityControllerTest extends WebTestCase
{ {
use PrepareClientTrait; use PrepareClientTrait;
private KernelBrowser $client;
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp();
self::bootKernel();
$this->client = $this->getClientAuthenticated(); $this->client = $this->getClientAuthenticated();
} }
@ -57,6 +58,8 @@ final class AsideActivityControllerTest extends WebTestCase
yield [array_pop($asideActivityIds)['id']]; yield [array_pop($asideActivityIds)['id']];
yield [array_pop($asideActivityIds)['id']]; yield [array_pop($asideActivityIds)['id']];
self::ensureKernelShutdown();
} }
/** /**

View File

@ -11,9 +11,11 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Tests\Controller; namespace Chill\CalendarBundle\Tests\Controller;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use function random_int; use function random_int;
@ -24,16 +26,21 @@ use function random_int;
*/ */
final class CalendarControllerTest extends WebTestCase final class CalendarControllerTest extends WebTestCase
{ {
use PrepareClientTrait;
private KernelBrowser $client;
/** /**
* Setup before each test method (see phpunit doc). * Setup before each test method (see phpunit doc).
*/ */
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); $this->client = $this->getClientAuthenticated();
$this->client = self::createClient([], [ }
'PHP_AUTH_USER' => 'center a_social',
'PHP_AUTH_PW' => 'password', protected function tearDown(): void
]); {
self::ensureKernelShutdown();
} }
public function provideAccompanyingPeriod(): iterable public function provideAccompanyingPeriod(): iterable
@ -73,6 +80,8 @@ final class CalendarControllerTest extends WebTestCase
->getQuery() ->getQuery()
->getSingleScalarResult(), ->getSingleScalarResult(),
]; ];
self::ensureKernelShutdown();
} }
/** /**

View File

@ -48,9 +48,9 @@ final class RemoteCalendarMSGraphSyncControllerTest extends WebTestCase
} }
JSON; JSON;
protected function setUp(): void protected function tearDown(): void
{ {
self::bootKernel(); self::ensureKernelShutdown();
} }
public function testSendNotification(): void public function testSendNotification(): void

View File

@ -67,7 +67,7 @@ class PersonDocumentGenericDocProviderTest extends KernelTestCase
['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query); ['sql' => $sql, 'params' => $params, 'types' => $types] = (new FetchQueryToSqlBuilder())->toSql($query);
$nb = $this->entityManager->getConnection() $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"); self::assertIsInt($nb, "Test that the query is syntactically correct");
} }

View File

@ -279,7 +279,7 @@ class EventController extends AbstractController
/** /**
* @var Center $centers * @var Center $centers
*/ */
$centers = $this->authorizationHelper->getReachableCenters($this->getUser(), (string) $role); $centers = $this->authorizationHelper->getReachableCenters($this->getUser(), $role);
if (count($centers) === 1) { if (count($centers) === 1) {
return $this->redirectToRoute('chill_event__event_new', [ return $this->redirectToRoute('chill_event__event_new', [

View File

@ -26,13 +26,12 @@ final class AddressControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\W
private KernelBrowser $client; private KernelBrowser $client;
protected function setUp(): void protected function tearDown(): void
{ {
self::bootKernel(); self::ensureKernelShutdown();
$this->client = $this->getClientAuthenticated();
} }
public function generateAddressIds() public function generateAddressIds(): iterable
{ {
self::bootKernel(); self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class); $em = self::$container->get(EntityManagerInterface::class);
@ -46,6 +45,8 @@ final class AddressControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\W
foreach ($addresses as $a) { foreach ($addresses as $a) {
yield [$a->getId()]; yield [$a->getId()];
} }
self::ensureKernelShutdown();
} }
/** /**
@ -53,6 +54,7 @@ final class AddressControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\W
*/ */
public function testDuplicate(int $addressId) public function testDuplicate(int $addressId)
{ {
$this->client = $this->getClientAuthenticated();
$this->client->request('POST', "/api/1.0/main/address/{$addressId}/duplicate.json"); $this->client->request('POST', "/api/1.0/main/address/{$addressId}/duplicate.json");
$this->assertResponseIsSuccessful('test that duplicate is successful'); $this->assertResponseIsSuccessful('test that duplicate is successful');

View File

@ -31,10 +31,14 @@ class AddressToReferenceMatcherControllerTest extends WebTestCase
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel();
$this->addressRepository = self::$container->get(AddressRepository::class); $this->addressRepository = self::$container->get(AddressRepository::class);
} }
protected function tearDown(): void
{
self::ensureKernelShutdown();
}
/** /**
* @dataProvider addressToReviewProvider * @dataProvider addressToReviewProvider
*/ */
@ -92,6 +96,8 @@ class AddressToReferenceMatcherControllerTest extends WebTestCase
$em->flush(); $em->flush();
yield [$address->getId()]; yield [$address->getId()];
self::ensureKernelShutdown();
} }
public static function addressUnsyncedProvider(): iterable public static function addressUnsyncedProvider(): iterable
@ -123,5 +129,7 @@ class AddressToReferenceMatcherControllerTest extends WebTestCase
$em->flush(); $em->flush();
yield [$address->getId()]; yield [$address->getId()];
self::ensureKernelShutdown();
} }
} }

View File

@ -23,8 +23,15 @@ final class PermissionApiControllerTest extends WebTestCase
{ {
use PrepareClientTrait; use PrepareClientTrait;
protected function tearDown(): void
{
self::ensureKernelShutdown();
}
public function testDenormalizingObject() public function testDenormalizingObject()
{ {
// for a unknown reason, the kernel may be booted before running this test...
self::ensureKernelShutdown();
$client = $this->getClientAuthenticated(); $client = $this->getClientAuthenticated();
$client->request( $client->request(

View File

@ -29,8 +29,6 @@ final class UserControllerTest extends WebTestCase
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel();
$this->client = self::createClient([], [ $this->client = self::createClient([], [
'PHP_AUTH_USER' => 'admin', 'PHP_AUTH_USER' => 'admin',
'PHP_AUTH_PW' => 'password', 'PHP_AUTH_PW' => 'password',
@ -49,6 +47,7 @@ final class UserControllerTest extends WebTestCase
} }
$em->flush(); $em->flush();
self::ensureKernelShutdown();
} }
public function dataGenerateUserId() public function dataGenerateUserId()
@ -69,6 +68,8 @@ final class UserControllerTest extends WebTestCase
$this->toDelete[] = [User::class, $user->getId()]; $this->toDelete[] = [User::class, $user->getId()];
yield [$user->getId(), $user->getUsername()]; yield [$user->getId(), $user->getUsername()];
self::ensureKernelShutdown();
} }
public function testList() public function testList()

View File

@ -34,9 +34,8 @@ final class DefaultScopeResolverTest extends TestCase
{ {
$scope = new Scope(); $scope = new Scope();
$entity = new class ($scope) implements HasScopeInterface { $entity = new class ($scope) implements HasScopeInterface {
public function __construct(Scope $scope) public function __construct(private readonly Scope $scope)
{ {
$this->scope = $scope;
} }
public function getScope() public function getScope()
@ -53,9 +52,8 @@ final class DefaultScopeResolverTest extends TestCase
public function testHasScopesInterface() public function testHasScopesInterface()
{ {
$entity = new class ($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface { $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 public function getScopes(): iterable

View File

@ -35,9 +35,8 @@ final class ScopeResolverDispatcherTest extends TestCase
{ {
$scope = new Scope(); $scope = new Scope();
$entity = new class ($scope) implements HasScopeInterface { $entity = new class ($scope) implements HasScopeInterface {
public function __construct(Scope $scope) public function __construct(private readonly Scope $scope)
{ {
$this->scope = $scope;
} }
public function getScope() public function getScope()
@ -53,6 +52,10 @@ final class ScopeResolverDispatcherTest extends TestCase
public function testHasScopesInterface() public function testHasScopesInterface()
{ {
$entity = new class ($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface { $entity = new class ($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface {
/**
* @var Scope[]
*/
private array $scopes = [];
public function __construct(Scope $scopeA, Scope $scopeB) public function __construct(Scope $scopeA, Scope $scopeB)
{ {
$this->scopes = [$scopeA, $scopeB]; $this->scopes = [$scopeA, $scopeB];

View File

@ -12,7 +12,9 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\AccompanyingPeriod; namespace Chill\PersonBundle\Tests\AccompanyingPeriod;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/** /**
@ -21,23 +23,21 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/ */
final class AccompanyingPeriodConfidentialTest extends WebTestCase final class AccompanyingPeriodConfidentialTest extends WebTestCase
{ {
/** use PrepareClientTrait;
* Setup before the first test of this class (see phpunit doc).
*/ private KernelBrowser $client;
public static function setUpBeforeClass(): void
{
self::bootKernel();
}
/** /**
* Setup before each test method (see phpunit doc). * Setup before each test method (see phpunit doc).
*/ */
protected function setUp(): void protected function setUp(): void
{ {
$this->client = self::createClient([], [ $this->client = $this->getClientAuthenticated();
'PHP_AUTH_USER' => 'fred', }
'PHP_AUTH_PW' => 'password',
]); protected function tearDown(): void
{
self::ensureKernelShutdown();
} }
/** /**

View File

@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Tests\Controller;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Test\PrepareClientTrait;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
@ -22,6 +23,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTime; use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Iterator; use Iterator;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use function array_map; use function array_map;
@ -40,31 +42,29 @@ use function json_encode;
*/ */
final class AccompanyingCourseApiControllerTest extends WebTestCase 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;
/** private ?int $personId = null;
* Setup before the first test of this class (see phpunit doc).
*/ private KernelBrowser $client;
public static function setUpBeforeClass(): void
{
self::bootKernel();
}
/** /**
* Setup before each test method (see phpunit doc). * Setup before each test method (see phpunit doc).
*/ */
protected function setUp(): void protected function setUp(): void
{ {
$this->client = self::createClient([], [ $this->client = $this->getClientAuthenticated();
'PHP_AUTH_USER' => 'center a_social', }
'PHP_AUTH_PW' => 'password',
]); protected function tearDown(): void
{
self::ensureKernelShutdown();
} }
public function dataGenerateNewAccompanyingCourse() public function dataGenerateNewAccompanyingCourse()
@ -100,6 +100,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
$em->flush(); $em->flush();
yield [$period]; yield [$period];
self::ensureKernelShutdown();
} }
public function dataGenerateRandomAccompanyingCourse() public function dataGenerateRandomAccompanyingCourse()
@ -165,6 +167,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
++$nbGenerated; ++$nbGenerated;
} }
self::ensureKernelShutdown();
} }
public function dataGenerateRandomAccompanyingCourseWithSocialIssue() public function dataGenerateRandomAccompanyingCourseWithSocialIssue()
@ -235,6 +239,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
++$nbGenerated; ++$nbGenerated;
} }
self::ensureKernelShutdown();
} }
public function dataGenerateRandomRequestorValidData(): Iterator public function dataGenerateRandomRequestorValidData(): Iterator
@ -302,6 +308,8 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
yield [$period, array_pop($personIds)['id'], array_pop($thirdPartyIds)['id']]; yield [$period, array_pop($personIds)['id'], array_pop($thirdPartyIds)['id']];
++$i; ++$i;
} }
self::ensureKernelShutdown();
} }
/** /**

View File

@ -19,6 +19,7 @@ use Chill\PersonBundle\Entity\Person;
use DateTime; use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Iterator; use Iterator;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use function array_pop; use function array_pop;
use function count; use function count;
@ -32,13 +33,18 @@ final class AccompanyingCourseControllerTest extends WebTestCase
{ {
use PrepareClientTrait; use PrepareClientTrait;
private KernelBrowser $client;
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp();
self::bootKernel();
$this->client = $this->getClientAuthenticated(); $this->client = $this->getClientAuthenticated();
} }
protected function tearDown(): void
{
self::ensureKernelShutdown();
}
public function dataGenerateRandomUsers(): Iterator public function dataGenerateRandomUsers(): Iterator
{ {
self::bootKernel(); self::bootKernel();
@ -61,6 +67,8 @@ final class AccompanyingCourseControllerTest extends WebTestCase
->getScalarResult(); ->getScalarResult();
yield [array_pop($personIds), array_pop($personIds)]; yield [array_pop($personIds), array_pop($personIds)];
self::ensureKernelShutdown();
} }
public function testNewWithoutUsers() public function testNewWithoutUsers()

View File

@ -22,12 +22,6 @@ final class AccompanyingPeriodRegulationListControllerTest extends WebTestCase
{ {
use PrepareClientTrait; use PrepareClientTrait;
protected function setUp(): void
{
parent::setUp();
self::bootKernel();
}
public function testRegulationList(): void public function testRegulationList(): void
{ {
$client = $this->getClientAuthenticated(); $client = $this->getClientAuthenticated();
@ -35,5 +29,7 @@ final class AccompanyingPeriodRegulationListControllerTest extends WebTestCase
$client->request('GET', '/fr/person/periods/undispatched'); $client->request('GET', '/fr/person/periods/undispatched');
$this->assertResponseIsSuccessful(); $this->assertResponseIsSuccessful();
self::ensureKernelShutdown();
} }
} }

View File

@ -42,6 +42,7 @@ final class HouseholdApiControllerTest extends WebTestCase
protected function tearDown(): void protected function tearDown(): void
{ {
self::bootKernel(); self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class); $em = self::$container->get(EntityManagerInterface::class);
foreach ($this->toDelete as [$class, $id]) { foreach ($this->toDelete as [$class, $id]) {
@ -50,6 +51,8 @@ final class HouseholdApiControllerTest extends WebTestCase
} }
$em->flush(); $em->flush();
self::ensureKernelShutdown();
} }
public function generateHouseholdAssociatedWithAddressReference() public function generateHouseholdAssociatedWithAddressReference()
@ -91,6 +94,8 @@ final class HouseholdApiControllerTest extends WebTestCase
]; ];
yield [$reference->getId(), $h->getId()]; yield [$reference->getId(), $h->getId()];
self::ensureKernelShutdown();
} }
public function generateHouseholdId() public function generateHouseholdId()
@ -121,6 +126,8 @@ final class HouseholdApiControllerTest extends WebTestCase
yield [array_pop($householdIds)['id']]; yield [array_pop($householdIds)['id']];
yield [array_pop($householdIds)['id']]; yield [array_pop($householdIds)['id']];
self::ensureKernelShutdown();
} }
public function generatePersonId() public function generatePersonId()
@ -144,6 +151,8 @@ final class HouseholdApiControllerTest extends WebTestCase
->first()->getPerson(); ->first()->getPerson();
yield [$person->getId()]; yield [$person->getId()];
self::ensureKernelShutdown();
} }
/** /**

View File

@ -37,6 +37,11 @@ final class HouseholdControllerTest extends WebTestCase
$this->client = $this->getClientAuthenticated(); $this->client = $this->getClientAuthenticated();
} }
protected function tearDown(): void
{
self::ensureKernelShutdown();
}
public function generateValidHouseholdIds() public function generateValidHouseholdIds()
{ {
self::bootKernel(); self::bootKernel();
@ -60,6 +65,8 @@ final class HouseholdControllerTest extends WebTestCase
yield [array_pop($ids)['id']]; yield [array_pop($ids)['id']];
yield [array_pop($ids)['id']]; yield [array_pop($ids)['id']];
self::ensureKernelShutdown();
} }
/** /**

View File

@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Tests\Controller;
use Chill\MainBundle\Test\PrepareClientTrait; use Chill\MainBundle\Test\PrepareClientTrait;
use DateTime; use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DomCrawler\Form; use Symfony\Component\DomCrawler\Form;
@ -48,7 +49,7 @@ final class PersonControllerCreateTest extends WebTestCase
public static function tearDownAfterClass(): void public static function tearDownAfterClass(): void
{ {
self::bootKernel(); self::bootKernel();
$em = self::$kernel->getContainer()->get('doctrine.orm.entity_manager'); $em = self::$container->get(EntityManagerInterface::class);
//remove two people created during test //remove two people created during test
$jesus = $em->getRepository(\Chill\PersonBundle\Entity\Person::class) $jesus = $em->getRepository(\Chill\PersonBundle\Entity\Person::class)
@ -65,11 +66,12 @@ final class PersonControllerCreateTest extends WebTestCase
$em->remove($jesus2); $em->remove($jesus2);
} }
$em->flush(); $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() public function testAddAPersonPage()
{ {
$client = $this->client; $client = $this->getClientAuthenticated();
$crawler = $client->request('GET', '/fr/person/new'); $crawler = $client->request('GET', '/fr/person/new');
$this->assertTrue( $this->assertTrue(
@ -137,7 +139,7 @@ final class PersonControllerCreateTest extends WebTestCase
public function testReviewExistingDetectionInversedLastNameWithFirstName() public function testReviewExistingDetectionInversedLastNameWithFirstName()
{ {
$this->markTestSkipped(); $this->markTestSkipped();
$client = $this->client; $client = $this->getClientAuthenticated();
$crawler = $client->request('GET', '/fr/person/new'); $crawler = $client->request('GET', '/fr/person/new');
@ -173,7 +175,7 @@ final class PersonControllerCreateTest extends WebTestCase
*/ */
public function testValidForm() public function testValidForm()
{ {
$client = $this->client; $client = $this->getClientAuthenticated();
$crawler = $client->request('GET', '/fr/person/new'); $crawler = $client->request('GET', '/fr/person/new');
$form = $crawler->selectButton("Créer l'usager")->form(); $form = $crawler->selectButton("Créer l'usager")->form();

View File

@ -46,9 +46,11 @@ final class PersonControllerUpdateTest extends WebTestCase
*/ */
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); }
$this->client = $this->getClientAuthenticated(); protected function tearDown(): void
{
self::ensureKernelShutdown();
} }
public static function tearDownAfterClass(): void public static function tearDownAfterClass(): void
@ -68,6 +70,7 @@ final class PersonControllerUpdateTest extends WebTestCase
} }
$em->flush(); $em->flush();
self::ensureKernelShutdown();
} }
/** /**
@ -181,6 +184,8 @@ final class PersonControllerUpdateTest extends WebTestCase
$em->flush(); $em->flush();
yield [$person->getId()]; yield [$person->getId()];
self::ensureKernelShutdown();
} }
private function makeEditPath(int $personId): string private function makeEditPath(int $personId): string

View File

@ -30,9 +30,9 @@ final class PersonControllerViewTest extends WebTestCase
*/ */
private static array $toDelete = []; private static array $toDelete = [];
protected function setUp(): void protected function tearDown(): void
{ {
self::bootKernel(); self::ensureKernelShutdown();
} }
public static function tearDownAfterClass(): void public static function tearDownAfterClass(): void
@ -113,6 +113,8 @@ final class PersonControllerViewTest extends WebTestCase
$em->flush(); $em->flush();
yield [$person->getId()]; yield [$person->getId()];
self::ensureKernelShutdown();
} }
private function makeViewPath(int $personId): string private function makeViewPath(int $personId): string

View File

@ -30,8 +30,6 @@ final class RelationshipApiControllerTest extends WebTestCase
{ {
use PrepareClientTrait; use PrepareClientTrait;
private KernelBrowser $client;
/** /**
* A cache for all relations. * A cache for all relations.
* *
@ -39,10 +37,9 @@ final class RelationshipApiControllerTest extends WebTestCase
*/ */
private ?array $relations = null; private ?array $relations = null;
protected function setUp(): void protected function tearDown(): void
{ {
self::bootKernel(); self::ensureKernelShutdown();
$this->client = $this->getClientAuthenticated();
} }
public function personProvider(): array public function personProvider(): array
@ -70,6 +67,8 @@ final class RelationshipApiControllerTest extends WebTestCase
->setFirstResult(random_int(0, $countPersons - 1)) ->setFirstResult(random_int(0, $countPersons - 1))
->getSingleResult(); ->getSingleResult();
self::ensureKernelShutdown();
return [ return [
[$person->getId()], [$person->getId()],
]; ];
@ -101,6 +100,8 @@ final class RelationshipApiControllerTest extends WebTestCase
->setFirstResult(random_int(0, $countPersons - 1)) ->setFirstResult(random_int(0, $countPersons - 1))
->getResult(); ->getResult();
self::ensureKernelShutdown();
return [ return [
[$persons[0]->getId(), $persons[1]->getId(), $this->getRandomRelation($em)->getId(), true], [$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) 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(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode(), 'Test to see that API response returns a status code 200'); $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 public function testPostRelationship(mixed $fromPersonId, mixed $toPersonId, mixed $relationId, mixed $isReverse): void
{ {
$this->client->request( $client = $this->getClientAuthenticated();
$client->request(
Request::METHOD_POST, Request::METHOD_POST,
'/api/1.0/relations/relationship.json', '/api/1.0/relations/relationship.json',
[], [],
@ -137,7 +141,7 @@ final class RelationshipApiControllerTest extends WebTestCase
], JSON_THROW_ON_ERROR) ], JSON_THROW_ON_ERROR)
); );
$response = $this->client->getResponse(); $response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }

View File

@ -26,11 +26,9 @@ final class SocialIssueApiControllerTest extends WebTestCase
{ {
use PrepareClientTrait; use PrepareClientTrait;
protected function setUp(): void protected function tearDown(): void
{ {
parent::setUp(); self::ensureKernelShutdown();
self::bootKernel();
} }
/** /**

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Search; namespace Chill\PersonBundle\Tests\Search;
use Chill\MainBundle\Test\PrepareClientTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/** /**
@ -21,6 +22,13 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/ */
final class PersonSearchTest extends WebTestCase final class PersonSearchTest extends WebTestCase
{ {
use PrepareClientTrait;
protected function tearDown(): void
{
self::ensureKernelShutdown();
}
public function testDefaultAccented(): never public function testDefaultAccented(): never
{ {
$this->markTestSkipped('skipped until adapted to new fixtures'); $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()); $this->assertMatchesRegularExpression('/MANÇO/', $crawlerSpecial->filter('.list-with-period')->text());
self::ensureKernelShutdown();
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person lastname:manco'); $crawlerNoSpecial = $this->generateCrawlerForSearch('@person lastname:manco');
$this->assertMatchesRegularExpression('/MANÇO/', $crawlerNoSpecial->filter('.list-with-period')->text()); $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()); $this->assertMatchesRegularExpression('/Gérard/', $crawlerSpecial->filter('.list-with-period')->text());
self::ensureKernelShutdown();
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person firstname:Gerard'); $crawlerNoSpecial = $this->generateCrawlerForSearch('@person firstname:Gerard');
$this->assertMatchesRegularExpression('/Gérard/', $crawlerNoSpecial->filter('.list-with-period')->text()); $this->assertMatchesRegularExpression('/Gérard/', $crawlerNoSpecial->filter('.list-with-period')->text());
@ -197,13 +209,15 @@ final class PersonSearchTest extends WebTestCase
public function testSearchWithAuthorization() public function testSearchWithAuthorization()
{ {
$crawlerCanSee = $this->generateCrawlerForSearch('Gérard', 'center a_social'); $crawlerCanSee = $this->generateCrawlerForSearch('Gérard', 'center a_social');
$crawlerCannotSee = $this->generateCrawlerForSearch('Gérard', 'center b_social');
$this->assertMatchesRegularExpression( $this->assertMatchesRegularExpression(
'/DEPARDIEU/', '/DEPARDIEU/',
$crawlerCanSee->text(), $crawlerCanSee->text(),
'center a_social may see "Depardieu" in center a' 'center a_social may see "Depardieu" in center a'
); );
self::ensureKernelShutdown();
$crawlerCannotSee = $this->generateCrawlerForSearch('Gérard', 'center b_social');
$this->assertDoesNotMatchRegularExpression( $this->assertDoesNotMatchRegularExpression(
'/DEPARDIEU/', '/DEPARDIEU/',
$crawlerCannotSee->text(), $crawlerCannotSee->text(),
@ -229,9 +243,6 @@ final class PersonSearchTest extends WebTestCase
*/ */
private function getAuthenticatedClient(mixed $username = 'center a_social') private function getAuthenticatedClient(mixed $username = 'center a_social')
{ {
return self::createClient([], [ return $this->getClientAuthenticated($username);
'PHP_AUTH_USER' => $username,
'PHP_AUTH_PW' => 'password',
]);
} }
} }