Use test container to replace test services definitions

This commit is contained in:
Yassine Guedidi 2024-02-24 02:34:03 +01:00
parent 742742f67d
commit a221ec8348
7 changed files with 16 additions and 32 deletions

View File

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

View File

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

View File

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

View File

@ -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']);

View File

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

View File

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

View File

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