[FrameworkBundle] Make the TestBrowserToken interchangeable with other tokens

This commit is contained in:
Jordi Boggiano 2021-03-05 11:17:34 +01:00 committed by Nicolas Grekas
parent f72d5165fd
commit a4958ae7ad
2 changed files with 11 additions and 2 deletions

View File

@ -120,7 +120,7 @@ class KernelBrowser extends HttpKernelBrowser
throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, UserInterface::class, \is_object($user) ? \get_class($user) : \gettype($user)));
}
$token = new TestBrowserToken($user->getRoles(), $user);
$token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);
$token->setAuthenticated(true);
$session = $this->getContainer()->get('session');
$session->set('_security_'.$firewallContext, serialize($token));

View File

@ -21,13 +21,22 @@ use Symfony\Component\Security\Core\User\UserInterface;
*/
class TestBrowserToken extends AbstractToken
{
public function __construct(array $roles = [], UserInterface $user = null)
private $firewallName;
public function __construct(array $roles = [], UserInterface $user = null, string $firewallName = 'main')
{
parent::__construct($roles);
if (null !== $user) {
$this->setUser($user);
}
$this->firewallName = $firewallName;
}
public function getFirewallName(): string
{
return $this->firewallName;
}
public function getCredentials()