Skip to content

Commit

Permalink
Avoid deprecation warnings in Symfony 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek authored and scheb committed Aug 11, 2021
1 parent 70886d7 commit 57f35c9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ public function __call(string $method, array $arguments)

private function getRequest(): Request
{
$request = $this->requestStack->getMasterRequest();
// Compatibility for Symfony >= 5.3
if (method_exists(RequestStack::class, 'getMainRequest')) {
$request = $this->requestStack->getMainRequest();
} else {
$request = $this->requestStack->getMasterRequest();
}
if (null === $request) {
throw new \RuntimeException('No request available');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ public function onAuthenticationTokenCreated(AuthenticationTokenCreatedEvent $ev

private function getRequest(): Request
{
$request = $this->requestStack->getMasterRequest();
// Compatibility for Symfony >= 5.3
if (method_exists(RequestStack::class, 'getMainRequest')) {
$request = $this->requestStack->getMainRequest();
} else {
$request = $this->requestStack->getMasterRequest();
}
if (null === $request) {
throw new \RuntimeException('No request available');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ private function readCookieValue(): ?string

private function getRequest(): Request
{
$request = $this->requestStack->getMasterRequest();
// Compatibility for Symfony >= 5.3
if (method_exists(RequestStack::class, 'getMainRequest')) {
$request = $this->requestStack->getMainRequest();
} else {
$request = $this->requestStack->getMasterRequest();
}
if (null === $request) {
throw new \RuntimeException('No request available');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ protected function setUp(): void
$this->firewallMap = $this->createMock(FirewallMap::class);

$this->requestStack = $this->createMock(RequestStack::class);
// Compatibility for Symfony >= 5.3
if (method_exists(RequestStack::class, 'getMainRequest')) {
$method = 'getMainRequest';
} else {
$method = 'getMasterRequest';
}
$this->requestStack
->expects($this->any())
->method('getMasterRequest')
->method($method)
->willReturn($this->createMock(Request::class));

$this->decorator = new AuthenticationProviderDecorator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ protected function setUp(): void
$this->authenticationContextFactory = $this->createMock(AuthenticationContextFactoryInterface::class);

$this->requestStack = $this->createMock(RequestStack::class);
// Compatibility for Symfony >= 5.3
if (method_exists(RequestStack::class, 'getMainRequest')) {
$method = 'getMainRequest';
} else {
$method = 'getMasterRequest';
}
$this->requestStack
->expects($this->any())
->method('getMasterRequest')
->method($method)
->willReturn($this->createMock(Request::class));

$this->listener = new AuthenticationTokenListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ protected function setUp(): void
$this->tokenEncoder = $this->createMock(TrustedDeviceTokenEncoder::class);
$this->request = new Request();
$requestStack = $this->createMock(RequestStack::class);
// Compatibility for Symfony >= 5.3
if (method_exists(RequestStack::class, 'getMainRequest')) {
$method = 'getMainRequest';
} else {
$method = 'getMasterRequest';
}
$requestStack
->expects($this->any())
->method('getMasterRequest')
->method($method)
->willReturn($this->request);

$this->tokenStorage = new TrustedDeviceTokenStorage($requestStack, $this->tokenEncoder, 'cookieName');
Expand Down

0 comments on commit 57f35c9

Please sign in to comment.