E
E
EVOSandru62021-08-19 13:04:38
symfony
EVOSandru6, 2021-08-19 13:04:38

What am I doing wrong when calling $this->client->loginUser in a test in Symfony 5.3?

Hey guys.
Symfony 5.3
What am I doing wrong when calling $this->client->loginUserin a test?

class DbWebTestCase extends WebTestCase
{
...
protected function setUp(): void
{
    $this->client = static::createClient();
    $this->client->disableReboot();
    $kernel = self::bootKernel();
    DatabasePrimer::prime($kernel);
    $this->em = $kernel->getContainer()->get('doctrine')->getManager();
}

public function test_userinfo_success()
{
    $userRepository = $this->em->getRepository(User::class);
    $testUser = $userRepository->findOneBy(['email' => '[email protected]']);

    // ТУТ РУГАЕТСЯ
    $this->client->loginUser($testUser);
}
...


LogicException: Cannot retrieve the container from a non-booted kernel.

If I do it like this:

protected function setUp(): void
    {
        $this->client = static::createClient();
        $this->client->disableReboot();
        $this->em = static::getContainer()->get('doctrine')->getManager();
}

public function test_userinfo_success()
        $userRepository = $this->em->getRepository(User::class);
        $testUser = $userRepository->findOneBy(['email' => '[email protected]']);
        $this->client->loginUser($testUser);
}


I am getting the following error:

You have requested a non-existent service "security.untracked_token_storage"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question