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)
5656 return ;
5757 }
5858
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+ }
6266
6367 // Order is not important for roles and should not change hash.
6468 sort ($ roles );
Original file line number Diff line number Diff line change 1515use FOS \HttpCacheBundle \UserContext \RoleProvider ;
1616use Mockery \Adapter \Phpunit \MockeryPHPUnitIntegration ;
1717use PHPUnit \Framework \TestCase ;
18+ use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
1819use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
1920use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
2021use Symfony \Component \Security \Core \Role \Role ;
@@ -25,13 +26,18 @@ class RoleProviderTest extends TestCase
2526
2627 public function testProvider ()
2728 {
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+ }
3138
3239 $ securityContext = $ this ->getTokenStorageMock ();
3340 $ securityContext ->shouldReceive ('getToken ' )->andReturn ($ token );
34- $ token ->shouldReceive ('getRoles ' )->andReturn ($ roles );
3541
3642 $ userContext = new UserContext ();
3743 $ provider = new RoleProvider ($ securityContext );
You can’t perform that action at this time.
0 commit comments