Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 274b518

Browse files
committed
Add 100% test coverage
1 parent 05a66e2 commit 274b518

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

src/Container/InMemoryRoleProviderFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace ZfcRbac\Container;
2323

2424
use Psr\Container\ContainerInterface;
25+
use ZfcRbac\Options\ModuleOptions;
2526
use ZfcRbac\Role\InMemoryRoleProvider;
2627

2728
/**
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15+
*
16+
* This software consists of voluntary contributions made by many individuals
17+
* and is licensed under the MIT license.
18+
*/
19+
20+
declare(strict_types=1);
21+
22+
namespace ZfcRbacTest\Container;
23+
24+
use PHPUnit\Framework\TestCase;
25+
use Zend\ServiceManager\ServiceManager;
26+
use ZfcRbac\Container\InMemoryRoleProviderFactory;
27+
use ZfcRbac\Options\ModuleOptions;
28+
use ZfcRbac\Role\InMemoryRoleProvider;
29+
30+
/**
31+
* @covers \ZfcRbac\Container\InMemoryRoleProviderFactory
32+
*/
33+
class InMemoryRoleProviderFactoryTest extends TestCase
34+
{
35+
public function testFactoryUsingObjectRepository(): void
36+
{
37+
$container = new ServiceManager();
38+
$container->setService(ModuleOptions::class, new ModuleOptions([
39+
'role_provider' => [
40+
InMemoryRoleProvider::class => [
41+
'admin' => [
42+
'children' => ['member'],
43+
'permissions' => ['delete'],
44+
],
45+
'member' => [
46+
'children' => ['guest'],
47+
'permissions' => ['write'],
48+
],
49+
'guest',
50+
],
51+
],
52+
]));
53+
54+
$roleProvider = (new InMemoryRoleProviderFactory())($container);
55+
$this->assertInstanceOf(InMemoryRoleProvider::class, $roleProvider);
56+
$this->assertCount(3, $roleProvider->getRoles(['admin', 'member', 'guest']));
57+
}
58+
}

test/RbacTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,20 @@ public function testReturnFalseIfNoHierarchicalRoleHasPermission(): void
114114

115115
$this->assertFalse($rbac->isGranted($parentRole, 'permission'));
116116
}
117+
118+
/**
119+
* @covers \ZfcRbac\Rbac::isGranted
120+
*/
121+
public function testCanCheckTraversableAsRolesList(): void
122+
{
123+
$role1 = new Role('Foo');
124+
125+
$role2 = new Role('Bar');
126+
$role2->addPermission('permission');
127+
128+
$roles = new \ArrayIterator([$role1, $role2]);
129+
$rbac = new Rbac();
130+
131+
$this->assertTrue($rbac->isGranted($roles, 'permission'));
132+
}
117133
}

0 commit comments

Comments
 (0)