mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +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:
@@ -28,7 +28,7 @@ trait PrepareCenterTrait
|
||||
/**
|
||||
* prepare a mocked center, with and id and name given.
|
||||
*/
|
||||
protected function prepareCenter(int $id, string $name): Center
|
||||
protected static function prepareCenter(int $id, string $name): Center
|
||||
{
|
||||
$center = new Center();
|
||||
$center->setName($name);
|
||||
|
@@ -28,7 +28,7 @@ trait PrepareScopeTrait
|
||||
*
|
||||
* The name will be present in both lang `fr` and `en`.
|
||||
*/
|
||||
protected function prepareScope(int $id, string $name): Scope
|
||||
protected static function prepareScope(int $id, string $name): Scope
|
||||
{
|
||||
$scope = new Scope();
|
||||
// set the name
|
||||
|
@@ -50,7 +50,7 @@ trait PrepareUserTrait
|
||||
*
|
||||
* @throws \LogicException if the trait is not set up
|
||||
*/
|
||||
protected function prepareUser(array $permissions)
|
||||
protected static function prepareUser(array $permissions)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
|
@@ -28,21 +28,23 @@ final class NotificationApiControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
private array $toDelete = [];
|
||||
private static array $toDelete = [];
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
foreach ($this->toDelete as [$className, $id]) {
|
||||
foreach (self::$toDelete as [$className, $id]) {
|
||||
$object = $em->find($className, $id);
|
||||
$em->remove($object);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
self::$toDelete = [];
|
||||
}
|
||||
|
||||
public function generateDataMarkAsRead()
|
||||
public static function generateDataMarkAsRead()
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
@@ -62,7 +64,9 @@ final class NotificationApiControllerTest extends WebTestCase
|
||||
$em->refresh($notification);
|
||||
$em->flush();
|
||||
|
||||
$this->toDelete[] = [Notification::class, $notification->getId()];
|
||||
self::$toDelete[] = [Notification::class, $notification->getId()];
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
|
||||
yield [$notification->getId()];
|
||||
}
|
||||
|
@@ -27,23 +27,7 @@ final class UserControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
private array $toDelete = [];
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
|
||||
foreach ($this->toDelete as [$class, $id]) {
|
||||
$obj = $em->getRepository($class)->find($id);
|
||||
$em->remove($obj);
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
|
||||
public function dataGenerateUserId()
|
||||
public static function dataGenerateUserId()
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::getContainer()->get(EntityManagerInterface::class);
|
||||
@@ -58,11 +42,9 @@ final class UserControllerTest extends WebTestCase
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
$this->toDelete[] = [User::class, $user->getId()];
|
||||
self::ensureKernelShutdown();
|
||||
|
||||
yield [$user->getId(), $user->getUsername()];
|
||||
|
||||
self::ensureKernelShutdown();
|
||||
}
|
||||
|
||||
public function testList()
|
||||
|
@@ -45,17 +45,17 @@ final class AuthorizationHelperTest extends KernelTestCase
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
public function dataProvider_getReachableCenters()
|
||||
public static function dataProvider_getReachableCenters()
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$centerA = $this->prepareCenter(1, 'center A');
|
||||
$centerB = $this->prepareCenter(2, 'center B');
|
||||
$scopeA = $this->prepareScope(1, 'scope default');
|
||||
$scopeB = $this->prepareScope(2, 'scope B');
|
||||
$scopeC = $this->prepareScope(3, 'scope C');
|
||||
$centerA = self::prepareCenter(1, 'center A');
|
||||
$centerB = self::prepareCenter(2, 'center B');
|
||||
$scopeA = self::prepareScope(1, 'scope default');
|
||||
$scopeB = self::prepareScope(2, 'scope B');
|
||||
$scopeC = self::prepareScope(3, 'scope C');
|
||||
|
||||
$userA = $this->prepareUser([
|
||||
$userA = self::prepareUser([
|
||||
[
|
||||
'center' => $centerA,
|
||||
'permissionsGroup' => [
|
||||
@@ -72,7 +72,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
||||
],
|
||||
]);
|
||||
|
||||
$ah = $this->getAuthorizationHelper();
|
||||
$ah = self::getAuthorizationHelper();
|
||||
|
||||
return [
|
||||
// without scopes
|
||||
@@ -143,15 +143,15 @@ final class AuthorizationHelperTest extends KernelTestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function dataProvider_getReachableScopes()
|
||||
public static function dataProvider_getReachableScopes()
|
||||
{
|
||||
$centerA = $this->prepareCenter(1, 'center A');
|
||||
$centerB = $this->prepareCenter(2, 'center B');
|
||||
$scopeA = $this->prepareScope(1, 'scope default');
|
||||
$scopeB = $this->prepareScope(2, 'scope B');
|
||||
$scopeC = $this->prepareScope(3, 'scope C');
|
||||
$centerA = self::prepareCenter(1, 'center A');
|
||||
$centerB = self::prepareCenter(2, 'center B');
|
||||
$scopeA = self::prepareScope(1, 'scope default');
|
||||
$scopeB = self::prepareScope(2, 'scope B');
|
||||
$scopeC = self::prepareScope(3, 'scope C');
|
||||
|
||||
$userA = $this->prepareUser([
|
||||
$userA = self::prepareUser([
|
||||
[
|
||||
'center' => $centerA,
|
||||
'permissionsGroup' => [
|
||||
@@ -579,7 +579,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
||||
/**
|
||||
* @return AuthorizationHelper
|
||||
*/
|
||||
private function getAuthorizationHelper()
|
||||
private static function getAuthorizationHelper()
|
||||
{
|
||||
return self::getContainer()
|
||||
->get(AuthorizationHelper::class);
|
||||
|
Reference in New Issue
Block a user