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

Skip to content

Commit be80f95

Browse files
committed
Fix compatibility with symfony/security-core 6.x
1 parent d7019da commit be80f95

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php

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

125125
$token = new TestBrowserToken($user->getRoles(), $user, $firewallContext);
126-
$token->setAuthenticated(true);
126+
if (method_exists($token, 'setAuthenticated')) {
127+
$token->setAuthenticated(true);
128+
}
127129

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

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ 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+
$token = new UsernamePasswordToken($user, 'pass', 'default', ['ROLE_USER']);
143+
} else {
144+
$token = new UsernamePasswordToken($user, 'default', ['ROLE_USER']);
145+
}
142146

143147
$controller = $this->createController();
144148
$controller->setContainer($this->getContainerWithTokenStorage($token));
@@ -148,6 +152,10 @@ public function testGetUser()
148152

149153
public function testGetUserAnonymousUserConvertedToNull()
150154
{
155+
if (!class_exists(AnonymousToken::class)) {
156+
$this->markTestSkipped('This test requires "symfony/security-core" <6.0.');
157+
}
158+
151159
$token = new AnonymousToken('default', 'anon.');
152160

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

0 commit comments

Comments
 (0)