Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Make the TestBrowserToken interchangeable with other tokens #40368

New issue

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

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function loginUser($user, string $firewallContext = 'main'): self
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));
Expand Down
11 changes: 10 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Test/TestBrowserToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@
*/
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()
Expand Down