-
Notifications
You must be signed in to change notification settings - Fork 181
Open
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
loginAs
and a user from your fixtures - Create the client
- Make a request on a simple controller doing, for example, a
refresh
of 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
setupFirewalls
with the client as parameter.
What do you think?