Skip to content

Commit 74f87b5

Browse files
committed
chore(symfony): remove deprecated test
1 parent b878e91 commit 74f87b5

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

src/Symfony/Security/ResourceAccessChecker.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ public function isGranted(string $resourceClass, string $expression, array $extr
3737
if (null === $this->tokenStorage || null === $this->authenticationTrustResolver) {
3838
throw new \LogicException('The "symfony/security" library must be installed to use the "security" attribute.');
3939
}
40-
if (null === $token = $this->tokenStorage->getToken()) {
41-
$token = new NullToken();
42-
}
40+
4341
if (null === $this->expressionLanguage) {
4442
throw new \LogicException('The "symfony/expression-language" library must be installed to use the "security" attribute.');
4543
}
@@ -49,10 +47,12 @@ public function isGranted(string $resourceClass, string $expression, array $extr
4947
'auth_checker' => $this->authorizationChecker, // needed for the is_granted expression function
5048
]);
5149

52-
if ($token) {
53-
$variables = array_merge($variables, $this->getVariables($token));
50+
if (null === $token = $this->tokenStorage->getToken()) {
51+
$token = new NullToken();
5452
}
5553

54+
$variables = array_merge($variables, $this->getVariables($token));
55+
5656
return (bool) $this->expressionLanguage->evaluate($expression, $variables);
5757
}
5858

tests/Symfony/Security/ResourceAccessCheckerTest.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,7 @@ public function testExpressionLanguageNotInstalled(): void
8383
$checker->isGranted(Dummy::class, 'is_granted("ROLE_ADMIN")');
8484
}
8585

86-
public function testNotBehindAFirewall(): void
87-
{
88-
$this->expectException(\LogicException::class);
89-
$this->expectExceptionMessage('The current token must be set to use the "security" attribute (is the URL behind a firewall?).');
90-
91-
$authenticationTrustResolverProphecy = $this->prophesize(AuthenticationTrustResolverInterface::class);
92-
$tokenStorageProphecy = $this->prophesize(TokenStorageInterface::class);
93-
94-
$checker = new ResourceAccessChecker(null, $authenticationTrustResolverProphecy->reveal(), null, $tokenStorageProphecy->reveal());
95-
$checker->isGranted(Dummy::class, 'is_granted("ROLE_ADMIN")');
96-
}
97-
98-
public function testWithoutAuthenticationTokenAndExceptionOnNoTokenIsFalse(): void
86+
public function testWithoutAuthenticationToken(): void
9987
{
10088
$expressionLanguageProphecy = $this->prophesize(ExpressionLanguage::class);
10189
$expressionLanguageProphecy->evaluate('is_granted("ROLE_ADMIN")', Argument::type('array'))->willReturn(true)->shouldBeCalled();
@@ -106,7 +94,7 @@ public function testWithoutAuthenticationTokenAndExceptionOnNoTokenIsFalse(): vo
10694

10795
$tokenStorageProphecy->getToken()->willReturn(null);
10896

109-
$checker = new ResourceAccessChecker($expressionLanguageProphecy->reveal(), $authenticationTrustResolverProphecy->reveal(), null, $tokenStorageProphecy->reveal(), $authorizationCheckerProphecy->reveal(), false);
97+
$checker = new ResourceAccessChecker($expressionLanguageProphecy->reveal(), $authenticationTrustResolverProphecy->reveal(), null, $tokenStorageProphecy->reveal(), $authorizationCheckerProphecy->reveal());
11098
self::assertTrue($checker->isGranted(Dummy::class, 'is_granted("ROLE_ADMIN")'));
11199
}
112100
}

0 commit comments

Comments
 (0)