1414use Symfony \Component \Security \Acl \Domain \RoleSecurityIdentity ;
1515use Symfony \Component \Security \Acl \Domain \UserSecurityIdentity ;
1616use Symfony \Component \Security \Acl \Domain \SecurityIdentityRetrievalStrategy ;
17+ use Symfony \Component \Security \Core \Role \Role ;
1718
1819class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
1920{
@@ -22,8 +23,6 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
2223 */
2324 public function testGetSecurityIdentities ($ user , array $ roles , $ authenticationStatus , array $ sids )
2425 {
25- $ strategy = $ this ->getStrategy ($ roles , $ authenticationStatus );
26-
2726 if ('anonymous ' === $ authenticationStatus ) {
2827 $ token = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken ' )
2928 ->disableOriginalConstructor ()
@@ -40,16 +39,20 @@ public function testGetSecurityIdentities($user, array $roles, $authenticationSt
4039 }
4140
4241 if (method_exists ($ token , 'getRoleNames ' )) {
42+ $ strategy = $ this ->getStrategy ($ roles , $ authenticationStatus , false );
43+
4344 $ token
4445 ->expects ($ this ->once ())
4546 ->method ('getRoleNames ' )
4647 ->will ($ this ->returnValue (array ('foo ' )))
4748 ;
4849 } else {
50+ $ strategy = $ this ->getStrategy ($ roles , $ authenticationStatus , true );
51+
4952 $ token
5053 ->expects ($ this ->once ())
5154 ->method ('getRoles ' )
52- ->will ($ this ->returnValue (array ('foo ' )))
55+ ->will ($ this ->returnValue (array (new Role ( 'foo ' ) )))
5356 ;
5457 }
5558
@@ -129,15 +132,32 @@ protected function getAccount($username, $class)
129132 return $ account ;
130133 }
131134
132- protected function getStrategy (array $ roles = array (), $ authenticationStatus = 'fullFledged ' )
135+ protected function getStrategy (array $ roles = array (), $ authenticationStatus = 'fullFledged ' , $ isBC = false )
133136 {
134- $ roleHierarchy = $ this ->getMock ('Symfony\Component\Security\Core\Role\RoleHierarchyInterface ' );
135- $ roleHierarchy
136- ->expects ($ this ->once ())
137- ->method ('getReachableRoles ' )
138- ->with ($ this ->equalTo (array ('foo ' )))
139- ->will ($ this ->returnValue ($ roles ))
140- ;
137+ $ roleHierarchyBuilder = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Role\RoleHierarchyInterface ' )
138+ ->disableProxyingToOriginalMethods ()
139+ ->disableOriginalConstructor ();
140+
141+ if ($ isBC ) {
142+ $ roleHierarchy = $ roleHierarchyBuilder ->setMethods (['getReachableRoles ' ])
143+ ->getMockForAbstractClass ();
144+
145+ $ roleHierarchy
146+ ->expects ($ this ->any ())
147+ ->method ('getReachableRoles ' )
148+ ->with ($ this ->equalTo ([new Role ('foo ' )]))
149+ ->will ($ this ->returnValue ($ roles ));
150+ } else {
151+ $ roleHierarchy = $ roleHierarchyBuilder ->setMethods (['getReachableRoleNames ' ])
152+ ->getMockForAbstractClass ();
153+
154+ $ roleHierarchy
155+ ->expects ($ this ->any ())
156+ ->method ('getReachableRoleNames ' )
157+ ->with ($ this ->equalTo (['foo ' ]))
158+ ->will ($ this ->returnValue ($ roles ));
159+ }
160+
141161
142162 $ trustResolver = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface ' , array (), array ('' , '' ));
143163
0 commit comments