Skip to content

Commit

Permalink
fix(token): fix getUsername calls only if there is no getUserIdentifi…
Browse files Browse the repository at this point in the history
…er method available (#71)

Co-authored-by: Emmanuel Drouet <[email protected]>
  • Loading branch information
noodle69 and Emmanuel Drouet authored Aug 9, 2022
1 parent 194de71 commit c406a5b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ protected function getUsername(): string
}

// compatibility Symfony < 6
if (method_exists($token, 'getUsername')) {
if (!method_exists($token, 'getUserIdentifier') &&
method_exists($token, 'getUsername')) {
return $token->getUsername();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ private function getUser(): UserInterface
private function getMockedToken()
{
$usernameMethod = 'getUserIdentifier';
if (method_exists(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class, 'getUsername')) {
if (!method_exists(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class, $usernameMethod) &&
method_exists(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class, 'getUsername')) {
// compatibility Symfony < 6
$usernameMethod = 'getUsername';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ private function getUser(): UserInterface
private function getMockedToken()
{
$usernameMethod = 'getUserIdentifier';
if (method_exists(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class, 'getUsername')) {
if (!method_exists(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class, $usernameMethod) &&
method_exists(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class, 'getUsername')) {
// compatibility Symfony < 6
$usernameMethod = 'getUsername';
}
Expand Down

0 comments on commit c406a5b

Please sign in to comment.