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

Skip to content

Commit 3fe93d6

Browse files
committed
bug #44427 [FrameworkBundle] Fix compatibility with symfony/security-core 6.x (deps=high tests) (wouterj)
This PR was merged into the 5.3 branch. Discussion ---------- [FrameworkBundle] Fix compatibility with symfony/security-core 6.x (deps=high tests) | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Complete diff of this PR must be removed when upmerging to 6.0. Commits ------- e044b17 Fix compatibility with symfony/security-core 6.x
2 parents d7019da + e044b17 commit 3fe93d6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ public function loginUser(object $user, string $firewallContext = 'main'): self
123123
}
124124

125125
$token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);
126-
$token->setAuthenticated(true);
126+
// @deprecated since Symfony 5.4
127+
if (method_exists($token, 'setAuthenticated')) {
128+
$token->setAuthenticated(true);
129+
}
127130

128131
$container = $this->getContainer();
129132
$container->get('security.untracked_token_storage')->setToken($token);

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ public function testForward()
138138
public function testGetUser()
139139
{
140140
$user = new InMemoryUser('user', 'pass');
141-
$token = new UsernamePasswordToken($user, 'pass', 'default', ['ROLE_USER']);
141+
if (method_exists(UsernamePasswordToken::class, 'setAuthenticated')) {
142+
// @deprecated since Symfony 5.4
143+
$token = new UsernamePasswordToken($user, 'pass', 'default', ['ROLE_USER']);
144+
} else {
145+
$token = new UsernamePasswordToken($user, 'default', ['ROLE_USER']);
146+
}
142147

143148
$controller = $this->createController();
144149
$controller->setContainer($this->getContainerWithTokenStorage($token));
@@ -148,6 +153,11 @@ public function testGetUser()
148153

149154
public function testGetUserAnonymousUserConvertedToNull()
150155
{
156+
// @deprecated since Symfony 5.4
157+
if (!class_exists(AnonymousToken::class)) {
158+
$this->markTestSkipped('This test requires "symfony/security-core" <6.0.');
159+
}
160+
151161
$token = new AnonymousToken('default', 'anon.');
152162

153163
$controller = $this->createController();

0 commit comments

Comments
 (0)