public getIdentityRoles ( ) : Rbac\Role\RoleInterface[] | ||
Résultat | Rbac\Role\RoleInterface[] |
public function getIdentityRoles()
{
if (!($identity = $this->getIdentity())) {
return $this->convertRoles([$this->guestRole]);
}
if (!$identity instanceof IdentityInterface) {
throw new Exception\RuntimeException(sprintf('ZfcRbac expects your identity to implement ZfcRbac\\Identity\\IdentityInterface, "%s" given', is_object($identity) ? get_class($identity) : gettype($identity)));
}
return $this->convertRoles($identity->getRoles());
}
public function testThrowExceptionIfIdentityIsWrongType() { $this->setExpectedException('ZfcRbac\\Exception\\RuntimeException', 'ZfcRbac expects your identity to implement ZfcRbac\\Identity\\IdentityInterface, "stdClass" given'); $identityProvider = $this->getMock('ZfcRbac\\Identity\\IdentityProviderInterface'); $identityProvider->expects($this->any())->method('getIdentity')->will($this->returnValue(new \stdClass())); $roleService = new RoleService($identityProvider, $this->getMock('ZfcRbac\\Role\\RoleProviderInterface'), $this->getMock('Rbac\\Traversal\\Strategy\\TraversalStrategyInterface')); $roleService->getIdentityRoles(); }