Skip to content

Commit d9fea1c

Browse files
bug #40368 [FrameworkBundle] Make the TestBrowserToken interchangeable with other tokens (Seldaek)
This PR was squashed before being merged into the 5.2 branch. Discussion ---------- [FrameworkBundle] Make the TestBrowserToken interchangeable with other tokens | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | For some reason most tokens implement getFirewallName (and the deprecated getProviderKey), but not all. This adds it to TestBrowserToken because it caused issues in my tests when upgrading to Symfony 5's `Client::loginUser()`. I am also happy to add this to AnonymousToken but I am more worried about BC impacts there, so I left it alone for now. All other token classes implement it, so I am not sure why this isn't in TokenInterface to begin with. Commits ------- a4958ae7ad [FrameworkBundle] Make the TestBrowserToken interchangeable with other tokens
2 parents 854bc9b + 4c00489 commit d9fea1c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

KernelBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function loginUser($user, string $firewallContext = 'main'): self
120120
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)));
121121
}
122122

123-
$token = new TestBrowserToken($user->getRoles(), $user);
123+
$token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);
124124
$token->setAuthenticated(true);
125125
$session = $this->getContainer()->get('session');
126126
$session->set('_security_'.$firewallContext, serialize($token));

Test/TestBrowserToken.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@
2121
*/
2222
class TestBrowserToken extends AbstractToken
2323
{
24-
public function __construct(array $roles = [], UserInterface $user = null)
24+
private $firewallName;
25+
26+
public function __construct(array $roles = [], UserInterface $user = null, string $firewallName = 'main')
2527
{
2628
parent::__construct($roles);
2729

2830
if (null !== $user) {
2931
$this->setUser($user);
3032
}
33+
34+
$this->firewallName = $firewallName;
35+
}
36+
37+
public function getFirewallName(): string
38+
{
39+
return $this->firewallName;
3140
}
3241

3342
public function getCredentials()

0 commit comments

Comments
 (0)