mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-04-04 20:13:42 +00:00
Change non-static class-level variables and methods to static in tests's data providers
The update modifies several test classes within the "chill-project" to change non-static class-level variables and methods to static ones. This change has been made to improve readability, performance, and to eliminate unnecessary instantiation of class objects in test scenarios. Also, flush and clear actions on the entity manager are moved to individual data providers.
This commit is contained in:
@@ -31,9 +31,9 @@ final class RelationshipApiControllerTest extends WebTestCase
|
||||
/**
|
||||
* A cache for all relations.
|
||||
*
|
||||
* @var array|Relation[]|null
|
||||
* @var array<int, Relation>|null
|
||||
*/
|
||||
private ?array $relations = null;
|
||||
private static ?array $relations = null;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
@@ -75,7 +75,7 @@ final class RelationshipApiControllerTest extends WebTestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function relationProvider(): array
|
||||
public static function relationProvider(): array
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
@@ -94,7 +94,7 @@ final class RelationshipApiControllerTest extends WebTestCase
|
||||
self::ensureKernelShutdown();
|
||||
|
||||
return [
|
||||
[$personIdWithoutRelations[0]['id'], $personIdWithoutRelations[1]['id'], $this->getRandomRelation($em)->getId(), true],
|
||||
[$personIdWithoutRelations[0]['id'], $personIdWithoutRelations[1]['id'], self::getRandomRelation($em)->getId(), true],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -137,13 +137,13 @@ final class RelationshipApiControllerTest extends WebTestCase
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
private function getRandomRelation(EntityManagerInterface $em): Relation
|
||||
private static function getRandomRelation(EntityManagerInterface $em): Relation
|
||||
{
|
||||
if (null === $this->relations) {
|
||||
$this->relations = $em->getRepository(Relation::class)
|
||||
if (null === self::$relations) {
|
||||
self::$relations = $em->getRepository(Relation::class)
|
||||
->findAll();
|
||||
}
|
||||
|
||||
return $this->relations[\array_rand($this->relations)];
|
||||
return self::$relations[\array_rand(self::$relations)];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user