20
20
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \Dummy ;
21
21
use PHPUnit \Framework \TestCase ;
22
22
use Prophecy \Argument ;
23
+ use Symfony \Bridge \PhpUnit \ExpectDeprecationTrait ;
23
24
use Symfony \Component \Security \Core \Authentication \AuthenticationTrustResolverInterface ;
24
25
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
25
26
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
30
31
*/
31
32
class ResourceAccessCheckerTest extends TestCase
32
33
{
34
+ use ExpectDeprecationTrait;
33
35
use ProphecyTrait;
34
36
35
37
/**
@@ -56,7 +58,7 @@ public function testIsGranted(bool $granted)
56
58
57
59
$ tokenStorageProphecy ->getToken ()->willReturn ($ token );
58
60
59
- $ checker = new ResourceAccessChecker ($ expressionLanguageProphecy ->reveal (), $ authenticationTrustResolverProphecy ->reveal (), null , $ tokenStorageProphecy ->reveal ());
61
+ $ checker = new ResourceAccessChecker ($ expressionLanguageProphecy ->reveal (), $ authenticationTrustResolverProphecy ->reveal (), null , $ tokenStorageProphecy ->reveal (), null , false );
60
62
$ this ->assertSame ($ granted , $ checker ->isGranted (Dummy::class, 'is_granted("ROLE_ADMIN") ' ));
61
63
}
62
64
@@ -70,7 +72,7 @@ public function testSecurityComponentNotAvailable()
70
72
$ this ->expectException (\LogicException::class);
71
73
$ this ->expectExceptionMessage ('The "symfony/security" library must be installed to use the "security" attribute. ' );
72
74
73
- $ checker = new ResourceAccessChecker ($ this ->prophesize (ExpressionLanguage::class)->reveal ());
75
+ $ checker = new ResourceAccessChecker ($ this ->prophesize (ExpressionLanguage::class)->reveal (), null , null , null , null , false );
74
76
$ checker ->isGranted (Dummy::class, 'is_granted("ROLE_ADMIN") ' );
75
77
}
76
78
@@ -83,19 +85,23 @@ public function testExpressionLanguageNotInstalled()
83
85
$ tokenStorageProphecy = $ this ->prophesize (TokenStorageInterface::class);
84
86
$ tokenStorageProphecy ->getToken ()->willReturn ($ this ->prophesize (TokenInterface::class)->willImplement (Serializable::class)->reveal ());
85
87
86
- $ checker = new ResourceAccessChecker (null , $ authenticationTrustResolverProphecy ->reveal (), null , $ tokenStorageProphecy ->reveal ());
88
+ $ checker = new ResourceAccessChecker (null , $ authenticationTrustResolverProphecy ->reveal (), null , $ tokenStorageProphecy ->reveal (), null , false );
87
89
$ checker ->isGranted (Dummy::class, 'is_granted("ROLE_ADMIN") ' );
88
90
}
89
91
92
+ /**
93
+ * @group legacy
94
+ */
90
95
public function testNotBehindAFirewall ()
91
96
{
97
+ $ this ->expectDeprecation ('Since api-platform/core 2.7: The $exceptionOnNoToken parameter in "ApiPlatform\Symfony\Security\ResourceAccessChecker::__construct()" is deprecated and will always be false in 3.0, you should stop using it. ' );
92
98
$ this ->expectException (\LogicException::class);
93
99
$ this ->expectExceptionMessage ('The current token must be set to use the "security" attribute (is the URL behind a firewall?). ' );
94
100
95
101
$ authenticationTrustResolverProphecy = $ this ->prophesize (AuthenticationTrustResolverInterface::class);
96
102
$ tokenStorageProphecy = $ this ->prophesize (TokenStorageInterface::class);
97
103
98
- $ checker = new ResourceAccessChecker (null , $ authenticationTrustResolverProphecy ->reveal (), null , $ tokenStorageProphecy ->reveal ());
104
+ $ checker = new ResourceAccessChecker (null , $ authenticationTrustResolverProphecy ->reveal (), null , $ tokenStorageProphecy ->reveal (), null , true );
99
105
$ checker ->isGranted (Dummy::class, 'is_granted("ROLE_ADMIN") ' );
100
106
}
101
107
0 commit comments