From a221ec83482cd6faf2535366b5ebc5a27cd90009 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 24 Feb 2024 02:34:03 +0100 Subject: [PATCH] Use test container to replace test services definitions --- app/config/services_test.yml | 17 ----------------- tests/Command/ReloadEntryCommandTest.php | 13 +++++++------ .../Controller/Api/DeveloperControllerTest.php | 2 +- tests/Controller/Api/WallabagApiTestCase.php | 4 ++-- tests/Controller/ConfigControllerTest.php | 3 ++- tests/Controller/ExportControllerTest.php | 5 ++--- tests/WallabagTestCase.php | 4 ++-- 7 files changed, 16 insertions(+), 32 deletions(-) diff --git a/app/config/services_test.yml b/app/config/services_test.yml index d55228614..9d894bb57 100644 --- a/app/config/services_test.yml +++ b/app/config/services_test.yml @@ -1,21 +1,4 @@ services: - # see https://github.com/symfony/symfony/issues/24543 - fos_user.user_manager.test: - alias: fos_user.user_manager - public: true - - fos_user.security.login_manager.test: - alias: fos_user.security.login_manager - public: true - - wallabag.entry_repository.test: - alias: Wallabag\Repository\EntryRepository - public: true - - wallabag_user.user_repository.test: - alias: Wallabag\Repository\UserRepository - public: true - filesystem_cache: class: Doctrine\Common\Cache\FilesystemCache arguments: diff --git a/tests/Command/ReloadEntryCommandTest.php b/tests/Command/ReloadEntryCommandTest.php index 7ea74a97a..717702632 100644 --- a/tests/Command/ReloadEntryCommandTest.php +++ b/tests/Command/ReloadEntryCommandTest.php @@ -6,6 +6,8 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Tests\Wallabag\WallabagTestCase; use Wallabag\Entity\Entry; +use Wallabag\Repository\EntryRepository; +use Wallabag\Repository\UserRepository; class ReloadEntryCommandTest extends WallabagTestCase { @@ -35,7 +37,7 @@ class ReloadEntryCommandTest extends WallabagTestCase { parent::setUp(); - $userRepository = $this->getTestClient()->getContainer()->get('wallabag_user.user_repository.test'); + $userRepository = static::getContainer()->get(UserRepository::class); $user = $userRepository->findOneByUserName('admin'); $this->adminEntry = new Entry($user); @@ -80,9 +82,8 @@ class ReloadEntryCommandTest extends WallabagTestCase 'interactive' => false, ]); - $reloadedEntries = $this->getTestClient() - ->getContainer() - ->get('wallabag.entry_repository.test') + $reloadedEntries = static::getContainer() + ->get(EntryRepository::class) ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); foreach ($reloadedEntries as $reloadedEntry) { @@ -107,7 +108,7 @@ class ReloadEntryCommandTest extends WallabagTestCase 'interactive' => false, ]); - $entryRepository = $this->getTestClient()->getContainer()->get('wallabag.entry_repository.test'); + $entryRepository = static::getContainer()->get(EntryRepository::class); $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); $this->assertNotEmpty($reloadedAdminEntry->getContent()); @@ -128,7 +129,7 @@ class ReloadEntryCommandTest extends WallabagTestCase '--only-not-parsed' => true, ]); - $entryRepository = $this->getTestClient()->getContainer()->get('wallabag.entry_repository.test'); + $entryRepository = static::getContainer()->get(EntryRepository::class); $reloadedBobParsedEntry = $entryRepository->find($this->bobParsedEntry->getId()); $this->assertEmpty($reloadedBobParsedEntry->getContent()); diff --git a/tests/Controller/Api/DeveloperControllerTest.php b/tests/Controller/Api/DeveloperControllerTest.php index 9c24efb9e..4fa29d4e1 100644 --- a/tests/Controller/Api/DeveloperControllerTest.php +++ b/tests/Controller/Api/DeveloperControllerTest.php @@ -132,7 +132,7 @@ class DeveloperControllerTest extends WallabagTestCase { $client = $this->getTestClient(); $em = $client->getContainer()->get(EntityManagerInterface::class); - $userManager = $client->getContainer()->get('fos_user.user_manager.test'); + $userManager = static::getContainer()->get('fos_user.user_manager'); $user = $userManager->findUserBy(['username' => $username]); $apiClient = new Client($user); $apiClient->setName('My app'); diff --git a/tests/Controller/Api/WallabagApiTestCase.php b/tests/Controller/Api/WallabagApiTestCase.php index 53d9f7ea9..1037ab4db 100644 --- a/tests/Controller/Api/WallabagApiTestCase.php +++ b/tests/Controller/Api/WallabagApiTestCase.php @@ -43,10 +43,10 @@ abstract class WallabagApiTestCase extends WebTestCase protected function createAuthorizedClient() { $client = $this->createUnauthorizedClient(); - $container = $client->getContainer(); + $container = static::getContainer(); /** @var UserManager $userManager */ - $userManager = $container->get('fos_user.user_manager.test'); + $userManager = $container->get('fos_user.user_manager'); $firewallName = $container->getParameter('fos_user.firewall_name'); $this->user = $userManager->findUserBy(['username' => 'admin']); diff --git a/tests/Controller/ConfigControllerTest.php b/tests/Controller/ConfigControllerTest.php index b86dca560..997378ba5 100644 --- a/tests/Controller/ConfigControllerTest.php +++ b/tests/Controller/ConfigControllerTest.php @@ -1313,7 +1313,8 @@ class ConfigControllerTest extends WallabagTestCase $client->submit($form, $data); $this->assertSame(302, $client->getResponse()->getStatusCode()); - $user = $client->getContainer()->get('fos_user.user_manager.test')->findUserBy(['username' => 'admin']); + $user = static::getContainer()->get('fos_user.user_manager')->findUserBy(['username' => 'admin']); + \assert($user instanceof User); $taggingRules = $user->getConfig()->getTaggingRules()->toArray(); $this->assertCount(5, $taggingRules); $this->assertSame('title matches "football"', $taggingRules[4]->getRule()); diff --git a/tests/Controller/ExportControllerTest.php b/tests/Controller/ExportControllerTest.php index a5cdfdb57..ffe2aa42a 100644 --- a/tests/Controller/ExportControllerTest.php +++ b/tests/Controller/ExportControllerTest.php @@ -5,6 +5,7 @@ namespace Tests\Wallabag\Controller; use Doctrine\ORM\EntityManagerInterface; use Tests\Wallabag\WallabagTestCase; use Wallabag\Entity\Entry; +use Wallabag\Repository\UserRepository; class ExportControllerTest extends WallabagTestCase { @@ -328,11 +329,9 @@ class ExportControllerTest extends WallabagTestCase private function setUpForJsonExportFromSearch() { - $client = $this->getTestClient(); $em = $this->getEntityManager(); - $userRepository = $client->getContainer() - ->get('wallabag_user.user_repository.test'); + $userRepository = static::getContainer()->get(UserRepository::class); $user = $userRepository->findOneByUserName('admin'); $this->adminEntry = new Entry($user); diff --git a/tests/WallabagTestCase.php b/tests/WallabagTestCase.php index 79ac54e40..c2df2ce35 100644 --- a/tests/WallabagTestCase.php +++ b/tests/WallabagTestCase.php @@ -86,9 +86,9 @@ abstract class WallabagTestCase extends WebTestCase */ public function logInAs($username) { - $container = $this->client->getContainer(); + $container = static::getContainer(); - $userManager = $container->get('fos_user.user_manager.test'); + $userManager = $container->get('fos_user.user_manager'); $firewallName = $container->getParameter('fos_user.firewall_name'); $user = $userManager->findUserBy(['username' => $username]);