Skip to content

Commit

Permalink
[AdminBundle] Fix getProviderKey deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat committed Oct 13, 2021
1 parent 1108f4d commit bb023ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/Kunstmaan/AdminBundle/EventListener/AdminLocaleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,20 @@ public function onKernelRequest($event)
*/
private function isAdminToken($providerKey, TokenInterface $token = null): bool
{
return \is_callable([$token, 'getProviderKey']) && $token->getProviderKey() === $providerKey;
if (null === $token) {
return false;
}

if (\is_callable([$token, 'getFirewallName'])) {
return $token->getFirewallName() === $providerKey;
}

// NEXT_MAJOR remove check when symfony 4.4 support is removed
if (\is_callable([$token, 'getProviderKey'])) {
return $token->getProviderKey() === $providerKey;
}

return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ public function testListener($uri, $shouldPerformCheck, $tokenStorageCallCount)
$adminRouteHelper = $this->createMock(AdminRouteHelper::class);
$kernel = $this->createMock(KernelInterface::class);
$event = class_exists(RequestEvent::class) ? new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST) : new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$token = $this->createMock(UsernamePasswordToken::class);
$user = $this->createMock(User::class);
$token = new UsernamePasswordToken($user, 'credentials', 'main');

$storage->expects($this->exactly($tokenStorageCallCount))->method('getToken')->willReturn($token);
$token->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('getProviderKey')->willReturn('main');
$token->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('getUser')->willReturn($user);
$user->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('getAdminLocale')->willReturn(null);
$trans->expects($this->exactly($shouldPerformCheck ? 1 : 0))->method('setLocale')->willReturn(null);
$adminRouteHelper->method('isAdminRoute')->willReturn($shouldPerformCheck);
Expand Down

0 comments on commit bb023ca

Please sign in to comment.