liip / liip/LiipFunctionalTestBundle

The firewall user shoyld be reloaded from the client entity manager

Open
#482 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
648
Forks
179
PR merge metrics
No merged PRs in 30d

Description

The user used on makeClient with createUserToken is loaded from fixtures and is not managed by the client entity manager.

This cause issue during test because doctrine considers it a new not managed entity,

Preconditions
  1. Have a user on fixtures
Steps to reproduce
  1. Authenticate your client with loginAs and a user from your fixtures
  2. Create the client
  3. Make a request on a simple controller doing, for example, a refresh of the user got from the token.
Expected result
  1. The refresh should work and any save with user association should be ok.
Actual result
  1. An error telling the entity is not managed by doctrine.

If I add a line to reload the user from the client doctrine service, it works:

foreach ($this->firewallLogins as $firewallName => $user) {
    // OVERRIDE
    $user = $client->getContainer()->get('doctrine')->getRepository(User::class)->find($user->getId());
    // END OVERRIDE
    $token = $this->createUserToken($user, $firewallName);

    $tokenStorage = $client->getContainer()->get('security.token_storage');

    $tokenStorage->setToken($token);
    $session->set('_security_'.$firewallName, serialize($token));
}

But I don't know how to do it properly.

Three possible solutions:

  1. Make this bundle reloading the user from the client all the time
  2. If not possible for some cases, make an option for that
  3. If it's a too much specific case for you, make the override easier with a method like setupFirewalls with the client as parameter.

What do you think?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the client setup used by makeClient, the firewallLogins loop, and createUserToken. Reproduce the fixture-backed login and refresh scenario, then determine whether reloading the user through the client Doctrine service or exposing a setupFirewalls override is appropriate. Done means the refreshed user is managed by the client entity manager and user associations can be saved without a Doctrine error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.