We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The user used on makeClient with createUserToken is loaded from fixtures and is not managed by the client entity manager.
makeClient
createUserToken
This cause issue during test because doctrine considers it a new not managed entity,
loginAs
refresh
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:
setupFirewalls
What do you think?
The text was updated successfully, but these errors were encountered:
The quick and dirty workaround I found so far:
namespace App\Security\Authentication; use AppBundle\Entity\User; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; final class TokenStorage implements TokenStorageInterface { /** * @var TokenStorageInterface */ private $decorated; /** * @var EntityManagerInterface */ private $entityManager; public function __construct(TokenStorageInterface $decorated, EntityManagerInterface $entityManager) { $this->decorated = $decorated; $this->entityManager = $entityManager; } /** * {@inheritdoc} */ public function getToken() { return $this->decorated->getToken(); } /** * {@inheritdoc} */ public function setToken(?TokenInterface $token = null) { $this->decorated->setToken($token); if (null === $token) { return; } $user = $token->getUser(); // @see https://github.com/liip/LiipFunctionalTestBundle/issues/482 if ($user instanceof User && !$this->entityManager->contains($user)) { $token->setUser($this->entityManager->getRepository(User::class)->find($user->getId())); } } }
And the service decoration declaration (under autowiring):
services: App\Security\Authentication\TokenStorage: decorates: security.token_storage
Sorry, something went wrong.
No branches or pull requests
The user used on
makeClient
withcreateUserToken
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
Steps to reproduce
loginAs
and a user from your fixturesrefresh
of the user got from the token.Expected result
Actual result
If I add a line to reload the user from the client doctrine service, it works:
But I don't know how to do it properly.
Three possible solutions:
setupFirewalls
with the client as parameter.What do you think?
The text was updated successfully, but these errors were encountered: