liip / liip/LiipFunctionalTestBundle
The firewall user shoyld be reloaded from the client entity manager
Nobody has claimed this yet.
- 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
- Have a user on fixtures
Steps to reproduce
- Authenticate your client with
loginAsand a user from your fixtures - Create the client
- Make a request on a simple controller doing, for example, a
refreshof the user got from the token.
Expected result
- The refresh should work and any save with user association should be ok.
Actual result
- 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:
- Make this bundle reloading the user from the client all the time
- If not possible for some cases, make an option for that
- If it's a too much specific case for you, make the override easier with a method like
setupFirewallswith the client as parameter.
What do you think?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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