From ffeba3818bdb567b808e8c4ecd7ea24abd3db142 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 9 Sep 2025 17:09:33 +0200 Subject: [PATCH] refactor: improve test setup and entity references in SingleTaskControllerTest - Remove unnecessary kernel boot in `setUp` - Use DI container retrieval for entity manager - Replace string class references with `::class` constants --- .../Controller/SingleTaskControllerTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Bundle/ChillTaskBundle/Tests/Controller/SingleTaskControllerTest.php b/src/Bundle/ChillTaskBundle/Tests/Controller/SingleTaskControllerTest.php index d416fbf06..b649606d9 100644 --- a/src/Bundle/ChillTaskBundle/Tests/Controller/SingleTaskControllerTest.php +++ b/src/Bundle/ChillTaskBundle/Tests/Controller/SingleTaskControllerTest.php @@ -13,6 +13,7 @@ namespace Chill\TaskBundle\Tests\Controller; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Tests\TestHelper; +use Chill\PersonBundle\Entity\Person; use Faker; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -30,7 +31,6 @@ final class SingleTaskControllerTest extends WebTestCase protected function setUp(): void { - self::bootKernel(); $this->faker = Faker\Factory::create('fr'); } @@ -75,26 +75,28 @@ final class SingleTaskControllerTest extends WebTestCase } /** - * @return \Chill\PersonBundle\Entity\Person + * @return Person */ protected function getRandomPerson(mixed $centerName) { - $em = self::$kernel - ->getContainer() + $container = self::getContainer(); + $em = $container ->get('doctrine.orm.entity_manager'); $centers = $em ->getRepository(Center::class) ->findAll(); - $center = \array_filter( - $centers, - static fn (Center $c) => $c->getName() === $centerName + $center = \array_values( + \array_filter( + $centers, + static fn (Center $c) => $c->getName() === $centerName + ) )[0]; $ids = $em ->createQuery( - 'SELECT p.id FROM ChillPersonBundle:Person p ' + 'SELECT p.id FROM '.Person::class.' p ' .'WHERE p.center = :center' ) ->setParameter('center', $center) @@ -102,10 +104,8 @@ final class SingleTaskControllerTest extends WebTestCase $id = $ids[\array_rand($ids)]; - return self::$kernel - ->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository(\Chill\PersonBundle\Entity\Person::class) + return $em + ->getRepository(Person::class) ->find($id); } }