Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#1 from wryck7/ZendHydr…
Browse files Browse the repository at this point in the history
…ator

CS fixes
  • Loading branch information
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
"dev-develop": "2.5-dev"
"dev-master": "2.1-dev",
"dev-develop": "2.2-dev"
}
},
"autoload-dev": {
Expand Down
6 changes: 5 additions & 1 deletion src/AbstractIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public function rewind()
*/
public function hasChildren()
{
return count($this->children) > 0;
if ($this->valid() && ($this->current() instanceof RecursiveIterator)) {
return true;
}

return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/AssertionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface AssertionInterface
/**
* Assertion method - must return a boolean.
*
* @param Rbac $bac
* @param Rbac $rbac
* @return boolean
*/
public function assert(Rbac $rbac);
Expand Down
11 changes: 7 additions & 4 deletions src/Rbac.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public function getCreateMissingRoles()
/**
* Add a child.
*
* @param string|RoleInterface $child
* @return RoleInterface
* @param string|RoleInterface $child
* @param array|RoleInterface|null $parents
* @return self
* @throws Exception\InvalidArgumentException
*/
public function addRole($child, $parents = null)
Expand Down Expand Up @@ -123,8 +124,10 @@ public function getRole($objectOrName)
/**
* Determines if access is granted by checking the role and child roles for permission.
*
* @param string $permission
* @param \Zend\Permissions\Rbac\AssertionInterface|Callable|null $assert
* @param RoleInterface|string $role
* @param string $permission
* @param AssertionInterface|Callable|null $assert
* @return bool
*/
public function isGranted($role, $permission, $assert = null)
{
Expand Down
20 changes: 20 additions & 0 deletions test/RbacTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,24 @@ public function testAddRoleWithAutomaticParentsUsingRbac()
$this->assertEquals($bar->getParent(), $foo);
$this->assertEquals(1, count($foo->getChildren()));
}

/**
* @tesdox Test adding custom child roles works
*/
public function testAddCustomChildRole()
{
$role = $this->getMockForAbstractClass('Zend\Permissions\Rbac\RoleInterface');
$this->rbac->setCreateMissingRoles(true)->addRole($role, array('parent'));

$role->expects($this->any())
->method('getName')
->will($this->returnValue('customchild'));

$role->expects($this->once())
->method('hasPermission')
->with('test')
->will($this->returnValue(true));

$this->assertTrue($this->rbac->isGranted('parent', 'test'));
}
}

0 comments on commit 7df306c

Please sign in to comment.