Remove deprecation linked to kernel shutdown

This commit is contained in:
2023-08-31 18:36:37 +02:00
parent 7c58880139
commit 6f11dffcbd
23 changed files with 166 additions and 85 deletions

View File

@@ -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();
}
/**

View File

@@ -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();
}
/**

View File

@@ -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()

View File

@@ -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();
}
}

View File

@@ -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();
}
/**

View File

@@ -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();
}
/**

View File

@@ -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();

View File

@@ -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

View File

@@ -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

View File

@@ -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());
}

View File

@@ -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();
}
/**

View File

@@ -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);
}
}