File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -56,9 +56,13 @@ public function updateUserContext(UserContext $context)
56
56
return ;
57
57
}
58
58
59
- $ roles = array_map (function (Role $ role ) {
60
- return $ role ->getRole ();
61
- }, $ token ->getRoles ());
59
+ if (method_exists ($ token , 'getRoleNames ' )) {
60
+ $ roles = $ token ->getRoleNames ();
61
+ } else {
62
+ $ roles = array_map (function (Role $ role ) {
63
+ return $ role ->getRole ();
64
+ }, $ token ->getRoles ());
65
+ }
62
66
63
67
// Order is not important for roles and should not change hash.
64
68
sort ($ roles );
Original file line number Diff line number Diff line change 15
15
use FOS \HttpCacheBundle \UserContext \RoleProvider ;
16
16
use Mockery \Adapter \Phpunit \MockeryPHPUnitIntegration ;
17
17
use PHPUnit \Framework \TestCase ;
18
+ use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
18
19
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
19
20
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
20
21
use Symfony \Component \Security \Core \Role \Role ;
@@ -25,13 +26,18 @@ class RoleProviderTest extends TestCase
25
26
26
27
public function testProvider ()
27
28
{
28
- $ roles = [new Role ('ROLE_USER ' )];
29
-
30
- $ token = \Mockery::mock (TokenInterface::class);
29
+ if (method_exists (AnonymousToken::class, 'getRoleNames ' )) {
30
+ $ token = \Mockery::mock (AnonymousToken::class);
31
+ $ token ->shouldReceive ('getRoleNames ' )->andReturn (['ROLE_USER ' ]);
32
+ $ token ->shouldNotReceive ('getRoles ' );
33
+ } else {
34
+ $ token = \Mockery::mock (TokenInterface::class);
35
+ $ token ->shouldReceive ('getRoles ' )->andReturn ([new Role ('ROLE_USER ' )]);
36
+ $ token ->shouldNotReceive ('getRoleNames ' );
37
+ }
31
38
32
39
$ securityContext = $ this ->getTokenStorageMock ();
33
40
$ securityContext ->shouldReceive ('getToken ' )->andReturn ($ token );
34
- $ token ->shouldReceive ('getRoles ' )->andReturn ($ roles );
35
41
36
42
$ userContext = new UserContext ();
37
43
$ provider = new RoleProvider ($ securityContext );
You can’t perform that action at this time.
0 commit comments