From 3dbb82d2ce66d3ecfb25f4d5e813da29044a6ef6 Mon Sep 17 00:00:00 2001 From: Leo Di Donato Date: Tue, 28 Oct 2014 02:57:48 +0100 Subject: [PATCH] Tests --- library/Assertion/AssertionPluginManager.php | 4 +- library/Exception/ExceptionInterface.php | 2 +- library/Exception/InvalidAssertException.php | 4 +- .../Exception/InvalidParameterException.php | 2 - .../ResourceAlreadyExistException.php | 4 +- .../Exception/ResourceNotExistException.php | 2 - .../Exception/RoleAlreadyExistException.php | 2 - library/Exception/RoleNotExistException.php | 2 - .../Exception/ServiceNotCreatedException.php | 3 +- library/Permission/GenericPermission.php | 36 +++-- library/Service/ServiceFactory.php | 4 +- .../Adapter/ArrayAdapter/ArrayAdapter.php | 14 +- tests/Assertion/AssertionAwareTraitTest.php | 3 + .../Assertion/AssertionManagerFactoryTest.php | 11 +- .../Assertion/AssertionPluginManagerTest.php | 10 +- .../TestAsset/Assertion/MockAssertion1.php | 26 +--- .../Assertion/MockWrongAssertion.php | 5 +- .../TestAsset/MockAssertionPluginManager.php | 18 +-- .../Service/ServiceAbstractTest.php | 42 ++++-- .../TestAsset/Assertion/Assertion1.php | 21 +-- .../TestAsset/Assertion/Assertion2.php | 21 +-- .../TestAsset/MockAssertionPluginManager.php | 17 +-- tests/Permission/GenericPermissionTest.php | 22 +-- tests/Role/RoleAwareTraitTest.php | 3 + tests/Service/ServiceAbstractTest.php | 49 ++++--- tests/Service/ServiceFactoryTest.php | 69 +++++++--- ...ArrayAdapterAbstractServiceFactoryTest.php | 41 +++--- .../Adapter/ArrayAdapter/ArrayAdapterTest.php | 128 +++++++++--------- tests/Storage/StorageAwareTraitTest.php | 5 +- tests/Storage/StorageFactoryTest.php | 39 +++--- tests/Storage/TestAsset/MockAdapter.php | 54 ++++---- 31 files changed, 327 insertions(+), 336 deletions(-) diff --git a/library/Assertion/AssertionPluginManager.php b/library/Assertion/AssertionPluginManager.php index 3f260df..a0923a3 100644 --- a/library/Assertion/AssertionPluginManager.php +++ b/library/Assertion/AssertionPluginManager.php @@ -8,7 +8,7 @@ */ namespace AclMan\Assertion; -use AlcMan\Exception\InvalidAssertException; +use AclMan\Exception\InvalidAssertException; use Zend\Permissions\Acl\Assertion\AssertionInterface; use Zend\ServiceManager\AbstractPluginManager; @@ -33,7 +33,7 @@ public function validatePlugin($plugin) } throw new InvalidAssertException(sprintf( - 'Plugin of type %s is invalid; must implement Zend\Permissions\Acl\Assertion\AssertionInterface', + 'Plugin of type "%s" is invalid; must implement Zend\Permissions\Acl\Assertion\AssertionInterface', (is_object($plugin) ? get_class($plugin) : gettype($plugin)) )); } diff --git a/library/Exception/ExceptionInterface.php b/library/Exception/ExceptionInterface.php index b709e09..b1b0bab 100644 --- a/library/Exception/ExceptionInterface.php +++ b/library/Exception/ExceptionInterface.php @@ -6,7 +6,7 @@ * @copyright Copyright (c) 2014, RipaClub * @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License */ -namespace AlcMan\Exception; +namespace AclMan\Exception; /** * Interface ExceptionInterface diff --git a/library/Exception/InvalidAssertException.php b/library/Exception/InvalidAssertException.php index b079c53..2b8cf80 100644 --- a/library/Exception/InvalidAssertException.php +++ b/library/Exception/InvalidAssertException.php @@ -6,11 +6,11 @@ * @copyright Copyright (c) 2014, RipaClub * @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License */ -namespace AlcMan\Exception; +namespace AclMan\Exception; /** * Class InvalidAssertException */ -class InvalidAssertException extends \Exception implements ExceptionInterface +class InvalidAssertException extends \RuntimeException implements ExceptionInterface { } diff --git a/library/Exception/InvalidParameterException.php b/library/Exception/InvalidParameterException.php index 0f92ea7..4b98cde 100644 --- a/library/Exception/InvalidParameterException.php +++ b/library/Exception/InvalidParameterException.php @@ -8,8 +8,6 @@ */ namespace AclMan\Exception; -use AlcMan\Exception\ExceptionInterface; - /** * Class InvalidParameterException */ diff --git a/library/Exception/ResourceAlreadyExistException.php b/library/Exception/ResourceAlreadyExistException.php index 4031f45..bfcd402 100644 --- a/library/Exception/ResourceAlreadyExistException.php +++ b/library/Exception/ResourceAlreadyExistException.php @@ -6,9 +6,7 @@ * @copyright Copyright (c) 2014, RipaClub * @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License */ -namespace AclMan\Storage\Exception; - -use AlcMan\Exception\ExceptionInterface; +namespace AclMan\Exception; /** * Class ResourceAlreadyExistException diff --git a/library/Exception/ResourceNotExistException.php b/library/Exception/ResourceNotExistException.php index fe90e71..e3233cd 100644 --- a/library/Exception/ResourceNotExistException.php +++ b/library/Exception/ResourceNotExistException.php @@ -8,8 +8,6 @@ */ namespace AclMan\Exception; -use AlcMan\Exception\ExceptionInterface; - /** * Class ResourceNotExistException */ diff --git a/library/Exception/RoleAlreadyExistException.php b/library/Exception/RoleAlreadyExistException.php index 074442f..d928229 100644 --- a/library/Exception/RoleAlreadyExistException.php +++ b/library/Exception/RoleAlreadyExistException.php @@ -8,8 +8,6 @@ */ namespace AclMan\Exception; -use AlcMan\Exception\ExceptionInterface; - /** * Class RoleAlreadyExistException */ diff --git a/library/Exception/RoleNotExistException.php b/library/Exception/RoleNotExistException.php index b0ca542..8af830d 100644 --- a/library/Exception/RoleNotExistException.php +++ b/library/Exception/RoleNotExistException.php @@ -8,8 +8,6 @@ */ namespace AclMan\Exception; -use AlcMan\Exception\ExceptionInterface; - /** * Class RoleNotExistException */ diff --git a/library/Exception/ServiceNotCreatedException.php b/library/Exception/ServiceNotCreatedException.php index abc52aa..e8890cb 100644 --- a/library/Exception/ServiceNotCreatedException.php +++ b/library/Exception/ServiceNotCreatedException.php @@ -6,9 +6,8 @@ * @copyright Copyright (c) 2014, RipaClub * @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License */ -namespace Exception; +namespace AclMan\Exception; -use AlcMan\Exception\ExceptionInterface; use Zend\ServiceManager\Exception\ServiceNotCreatedException as ZendServiceNotCreatedException; /** diff --git a/library/Permission/GenericPermission.php b/library/Permission/GenericPermission.php index 51d8524..957efa2 100644 --- a/library/Permission/GenericPermission.php +++ b/library/Permission/GenericPermission.php @@ -51,26 +51,22 @@ class GenericPermission implements PermissionInterface */ public function __construct($options = null) { - switch(true) { - case isset($options['role']): - $role = $this->checkRole($options['role']); - $this->roleId = $role->getRoleId(); - break; - case isset($options['resource']): - $resource = $this->checkResource($options['resource']); - $this->resourceId = $resource->getResourceId(); - break; - case isset($options['privilege']): - $this->setPrivilege($options['privilege']); - break; - case isset($options['allow']): - $this->allow = (bool) $options['allow']; - break; - case isset($options['assert']): - $this->setAssertion($options['assert']); - break; - default: - break; + if (isset($options['role'])) { + $role = $this->checkRole($options['role']); + $this->roleId = $role->getRoleId(); + } + if (isset($options['resource'])) { + $resource = $this->checkResource($options['resource']); + $this->resourceId = $resource->getResourceId(); + } + if (isset($options['privilege'])) { + $this->setPrivilege($options['privilege']); + } + if (isset($options['allow'])) { + $this->allow = (bool) $options['allow']; + } + if (isset($options['assert'])) { + $this->setAssertion($options['assert']); } } diff --git a/library/Service/ServiceFactory.php b/library/Service/ServiceFactory.php index d76c6bc..a368e60 100644 --- a/library/Service/ServiceFactory.php +++ b/library/Service/ServiceFactory.php @@ -9,7 +9,7 @@ namespace AclMan\Service; use AclMan\Storage\StorageInterface; -use Exception\ServiceNotCreatedException; +use AclMan\Exception\ServiceNotCreatedException; use Zend\Permissions\Acl\Acl; use Zend\ServiceManager\AbstractFactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -86,7 +86,7 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $ $storage = $serviceLocator->get($config['storage']); if (!$storage instanceof StorageInterface) { throw new ServiceNotCreatedException(sprintf( - '"%s" expectes a AclMan\Storage\StorageInterface; received "%s"', + '"%s" expectes a AclMan\Storage\StorageInterface is set in the config; received "%s"', __METHOD__, is_object($storage) ? get_class($storage) : gettype($storage) )); diff --git a/library/Storage/Adapter/ArrayAdapter/ArrayAdapter.php b/library/Storage/Adapter/ArrayAdapter/ArrayAdapter.php index 166d7ad..a6eb90e 100644 --- a/library/Storage/Adapter/ArrayAdapter/ArrayAdapter.php +++ b/library/Storage/Adapter/ArrayAdapter/ArrayAdapter.php @@ -17,7 +17,7 @@ use AclMan\Permission\PermissionInterface; use AclMan\Resource\ResourceCheckTrait; use AclMan\Role\RoleCheckTrait; -use AclMan\Storage\Exception\ResourceAlreadyExistException; +use AclMan\Exception\ResourceAlreadyExistException; use AclMan\Storage\StorageInterface; use Zend\Permissions\Acl\Resource\GenericResource; use Zend\Permissions\Acl\Resource\ResourceInterface; @@ -267,23 +267,27 @@ public function getPermissions($role = null, $resource = null) if ($resource) { $resource = $this->checkResource($resource); - $listPermission = $this->permission[$role->getRoleId()][self::NODE_RESOURCES][$resource->getResourceId()]; - if (isset($listPermission[self::NODE_PERMISSION])) { - $listPermission = $listPermission[self::NODE_PERMISSION]; + if(isset($this->permission[$role->getRoleId()][self::NODE_RESOURCES][$resource->getResourceId()][self::NODE_PERMISSION])) { + $listPermission = $this->permission[$role->getRoleId()][self::NODE_RESOURCES][$resource->getResourceId()][self::NODE_PERMISSION]; foreach ($listPermission as $permission) { + $permission['role'] = $role->getRoleId(); $permission['resource'] = $resource->getResourceId(); + $obj = new GenericPermission($permission); array_push($result, $obj); } + } } else { - if (isset($this->permission[$role->getRoleId()][self::NODE_RESOURCES])) { + if(isset($this->permission[$role->getRoleId()][self::NODE_RESOURCES])) { $listResource = $this->permission[$role->getRoleId()][self::NODE_RESOURCES]; foreach ($listResource as $keyResource => $listPermission) { foreach ($listPermission[self::NODE_PERMISSION] as $permission) { + $permission['role'] = $role->getRoleId(); $permission['resource'] = ($keyResource != self::ALL_RESOURCES) ? $keyResource : null; + $obj = new GenericPermission($permission); array_push($result, $obj); } diff --git a/tests/Assertion/AssertionAwareTraitTest.php b/tests/Assertion/AssertionAwareTraitTest.php index 0e5e604..5dd46cd 100644 --- a/tests/Assertion/AssertionAwareTraitTest.php +++ b/tests/Assertion/AssertionAwareTraitTest.php @@ -10,6 +10,9 @@ use AclManTest\AclManTestCase; +/** + * Class AssertionAwareTraitTest + */ class AssertionAwareTraitTest extends AclManTestCase { /** diff --git a/tests/Assertion/AssertionManagerFactoryTest.php b/tests/Assertion/AssertionManagerFactoryTest.php index 1a2d6c3..db34db8 100644 --- a/tests/Assertion/AssertionManagerFactoryTest.php +++ b/tests/Assertion/AssertionManagerFactoryTest.php @@ -9,6 +9,7 @@ namespace AclManTest\Assertion; use AclManTest\AclManTestCase; +use AclManTest\Assertion\TestAsset\MockAssertionPluginManager; use Zend\Mvc\Service\ServiceManagerConfig; use Zend\ServiceManager; @@ -24,11 +25,11 @@ class AssertionManagerFactoryTest extends AclManTestCase public function setUp() { - $config = array( + $config = [ 'factories' => [ 'assertManager' => 'AclMan\Assertion\AssertionManagerFactory', ] - ); + ]; $sm = $this->serviceManager = new ServiceManager\ServiceManager( new ServiceManagerConfig($config) @@ -45,14 +46,14 @@ public function testAssertPluginManager() public function testAssetPluginManagerCustom() { - $config = array( + $config = [ 'factories' => [ 'assertManager' => 'AclMan\Assertion\AssertionManagerFactory', ], 'invokables' => [ 'AclMan\Plugin\Manager' => 'AclManTest\Assertion\TestAsset\MockAssertionPluginManager' ] - ); + ]; $sm = new ServiceManager\ServiceManager( new ServiceManagerConfig($config) @@ -60,7 +61,7 @@ public function testAssetPluginManagerCustom() $sm->setService('Config', $config); - /** @var $pluginManager \AclManTest\Assert\TestAsset\MockAssertionPluginManager */ + /** @var $pluginManager MockAssertionPluginManager */ $pluginManager = $sm->get('assertManager'); $this->assertInstanceOf('AclManTest\Assertion\TestAsset\MockAssertionPluginManager', $pluginManager); } diff --git a/tests/Assertion/AssertionPluginManagerTest.php b/tests/Assertion/AssertionPluginManagerTest.php index a207ea4..0c93ffc 100644 --- a/tests/Assertion/AssertionPluginManagerTest.php +++ b/tests/Assertion/AssertionPluginManagerTest.php @@ -11,6 +11,9 @@ use AclMan\Assertion\AssertionPluginManager; use AclManTest\AclManTestCase; +/** + * Class AssertionPluginManagerTest + */ class AssertionPluginManagerTest extends AclManTestCase { protected $manager; @@ -24,11 +27,14 @@ public function setUp() public function testAssertionPluginManager() { - $this->assertInstanceOf('AclManTest\Assertion\TestAsset\Assertion\MockAssertion1', $this->manager->get('assert1')); + $this->assertInstanceOf( + 'AclManTest\Assertion\TestAsset\Assertion\MockAssertion1', + $this->manager->get('assert1') + ); } /** - * @expectedException \AclMan\Assertion\Exception\InvalidAssertException + * @expectedException \AclMan\Exception\InvalidAssertException */ public function testAssertionPluginManagerException() { diff --git a/tests/Assertion/TestAsset/Assertion/MockAssertion1.php b/tests/Assertion/TestAsset/Assertion/MockAssertion1.php index 9e66efe..05dae5a 100644 --- a/tests/Assertion/TestAsset/Assertion/MockAssertion1.php +++ b/tests/Assertion/TestAsset/Assertion/MockAssertion1.php @@ -15,34 +15,16 @@ use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait; +/** + * Class MockAssertion1 + */ class MockAssertion1 implements AssertionInterface, ServiceLocatorAwareInterface { - /** - * TRAIT - ******************************************************************************************************************/ - use ServiceLocatorAwareTrait; - /** - * METHOD - ******************************************************************************************************************/ - - /** - * Returns true if and only if the assertion conditions are met - * - * This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the - * $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or - * privileges, respectively. - * - * @param Acl $acl - * @param RoleInterface $role - * @param ResourceInterface $resource - * @param string $privilege - * @return bool - */ public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) { - // TODO: Implement assert() method. + // TODO: implement assert() method. } } diff --git a/tests/Assertion/TestAsset/Assertion/MockWrongAssertion.php b/tests/Assertion/TestAsset/Assertion/MockWrongAssertion.php index 9772461..4ed7fbf 100644 --- a/tests/Assertion/TestAsset/Assertion/MockWrongAssertion.php +++ b/tests/Assertion/TestAsset/Assertion/MockWrongAssertion.php @@ -8,8 +8,9 @@ */ namespace AclManTest\Assertion\TestAsset\Assertion; - +/** + * Class MockWrongAssertion + */ class MockWrongAssertion { - } diff --git a/tests/Assertion/TestAsset/MockAssertionPluginManager.php b/tests/Assertion/TestAsset/MockAssertionPluginManager.php index 4d37a66..08688fb 100644 --- a/tests/Assertion/TestAsset/MockAssertionPluginManager.php +++ b/tests/Assertion/TestAsset/MockAssertionPluginManager.php @@ -8,9 +8,13 @@ */ namespace AclManTest\Assertion\TestAsset; +use AclMan\Exception\InvalidAssertException; use Zend\Permissions\Acl\Assertion\AssertionInterface; use Zend\ServiceManager\AbstractPluginManager; +/** + * Class MockAssertionPluginManager + */ class MockAssertionPluginManager extends AbstractPluginManager { /** @@ -23,17 +27,7 @@ class MockAssertionPluginManager extends AbstractPluginManager ]; /** - * METHOD - ******************************************************************************************************************/ - - /** - * Validate the plugin - * - * Checks that the filter loaded is either a valid callback or an instance - * of FilterInterface. - * - * @param mixed $plugin - * @throws \Zend\ServiceManager\Exception\InvalidAssertException + * {@inheritdoc} */ public function validatePlugin($plugin) { @@ -41,7 +35,7 @@ public function validatePlugin($plugin) return; } - throw new \Exception(sprintf( + throw new InvalidAssertException(sprintf( 'Plugin of type %s is invalid; must implement Zend\Permissions\Acl\Assertion\AssertionInterface', (is_object($plugin) ? get_class($plugin) : gettype($plugin)) )); diff --git a/tests/Integration/Service/ServiceAbstractTest.php b/tests/Integration/Service/ServiceAbstractTest.php index 00ad045..8447aad 100644 --- a/tests/Integration/Service/ServiceAbstractTest.php +++ b/tests/Integration/Service/ServiceAbstractTest.php @@ -18,7 +18,11 @@ use Zend\Mvc\Service\ServiceManagerConfig; use Zend\ServiceManager; - +/** + * Class ServiceAbstractTest + * + * @grop integration + */ class ServiceAbstractTest extends AclManTestCase { /** @@ -37,14 +41,14 @@ public function setUp() 'resource1' => [ [ 'assert' => null, - 'allow' => true, + 'allow' => true, 'privilege' => 'view' ] ], 'resource2' => [ [ 'assert' => 'assertFalse', - 'allow' => true, + 'allow' => true, 'privilege' => 'view' ] ] @@ -58,19 +62,19 @@ public function setUp() 'resource1' => [ [ 'assert' => null, - 'allow' => true, + 'allow' => true, 'privilege' => 'add' ] ], 'resource2' => [ [ 'assert' => null, - 'allow' => true, + 'allow' => true, 'privilege' => 'add' ], [ 'assert' => 'assertTrue', - 'allow' => true, + 'allow' => true, 'privilege' => 'view' ] @@ -89,7 +93,8 @@ public function setUp() ]; $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig([ + new ServiceManagerConfig( + [ 'abstract_factories' => [ 'AclMan\Service\ServiceFactory', 'AclMan\Storage\StorageFactory' @@ -109,10 +114,9 @@ public function setUp() } - public function testHasService() { - $this->assertTrue($this->serviceManager->has('AclService')); + $this->assertTrue($this->serviceManager->has('AclService')); } /** @@ -145,10 +149,22 @@ public function testIsAllowed() $service = $this->serviceManager->get('AclService'); $service->init(); - $this->assertSame($acl->isAllowed('role1', 'resource1', 'view'), $service->isAllowed('role1', 'resource1', 'view')); - $this->assertSame($acl->isAllowed('role1', 'resource1', 'add'), $service->isAllowed('role1', 'resource1', 'add')); + $this->assertSame( + $acl->isAllowed('role1', 'resource1', 'view'), + $service->isAllowed('role1', 'resource1', 'view') + ); + $this->assertSame( + $acl->isAllowed('role1', 'resource1', 'add'), + $service->isAllowed('role1', 'resource1', 'add') + ); - $this->assertSame($acl->isAllowed('role2', 'resource1', 'view'), $service->isAllowed('role2', 'resource1', 'view')); - $this->assertSame($acl->isAllowed('role2', 'resource1', 'add'), $service->isAllowed('role2', 'resource1', 'add')); + $this->assertSame( + $acl->isAllowed('role2', 'resource1', 'view'), + $service->isAllowed('role2', 'resource1', 'view') + ); + $this->assertSame( + $acl->isAllowed('role2', 'resource1', 'add'), + $service->isAllowed('role2', 'resource1', 'add') + ); } } diff --git a/tests/Integration/Service/TestAsset/Assertion/Assertion1.php b/tests/Integration/Service/TestAsset/Assertion/Assertion1.php index 6f0e793..21b2c4a 100644 --- a/tests/Integration/Service/TestAsset/Assertion/Assertion1.php +++ b/tests/Integration/Service/TestAsset/Assertion/Assertion1.php @@ -15,31 +15,18 @@ use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait; +/** + * Class Assertion1 + */ class Assertion1 implements AssertionInterface, ServiceLocatorAwareInterface { - /** - * TRAIT - ******************************************************************************************************************/ - use ServiceLocatorAwareTrait; /** - * Returns true if and only if the assertion conditions are met - * - * This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the - * $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or - * privileges, respectively. - * - * @param Acl $acl - * @param RoleInterface $role - * @param ResourceInterface $resource - * @param string $privilege - * @return bool + * {@inheritdoc} */ public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) { return false; } - - } diff --git a/tests/Integration/Service/TestAsset/Assertion/Assertion2.php b/tests/Integration/Service/TestAsset/Assertion/Assertion2.php index 0cf8137..920c5bd 100644 --- a/tests/Integration/Service/TestAsset/Assertion/Assertion2.php +++ b/tests/Integration/Service/TestAsset/Assertion/Assertion2.php @@ -15,31 +15,18 @@ use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait; +/** + * Class Assertion2 + */ class Assertion2 implements AssertionInterface, ServiceLocatorAwareInterface { - /** - * TRAIT - ******************************************************************************************************************/ - use ServiceLocatorAwareTrait; /** - * Returns true if and only if the assertion conditions are met - * - * This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the - * $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or - * privileges, respectively. - * - * @param Acl $acl - * @param RoleInterface $role - * @param ResourceInterface $resource - * @param string $privilege - * @return bool + * {@inheritdoc} */ public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null) { return true; } - - } diff --git a/tests/Integration/Service/TestAsset/MockAssertionPluginManager.php b/tests/Integration/Service/TestAsset/MockAssertionPluginManager.php index 0e1f120..4779409 100644 --- a/tests/Integration/Service/TestAsset/MockAssertionPluginManager.php +++ b/tests/Integration/Service/TestAsset/MockAssertionPluginManager.php @@ -11,6 +11,9 @@ use Zend\Permissions\Acl\Assertion\AssertionInterface; use Zend\ServiceManager\AbstractPluginManager; +/** + * Class MockAssertionPluginManager + */ class MockAssertionPluginManager extends AbstractPluginManager { /** @@ -24,17 +27,7 @@ class MockAssertionPluginManager extends AbstractPluginManager ]; /** - * METHOD - ******************************************************************************************************************/ - - /** - * Validate the plugin - * - * Checks that the filter loaded is either a valid callback or an instance - * of FilterInterface. - * - * @param mixed $plugin - * @throws \Zend\ServiceManager\Exception\InvalidAssertException + * {@inheritdoc} */ public function validatePlugin($plugin) { @@ -43,7 +36,7 @@ public function validatePlugin($plugin) } throw new \Exception(sprintf( - 'Plugin of type %s is invalid; must implement Zend\Permissions\Acl\Assertion\AssertionInterface', + 'Plugin of type "%s" is invalid; must implement Zend\Permissions\Acl\Assertion\AssertionInterface', (is_object($plugin) ? get_class($plugin) : gettype($plugin)) )); } diff --git a/tests/Permission/GenericPermissionTest.php b/tests/Permission/GenericPermissionTest.php index 7cd8870..6696930 100644 --- a/tests/Permission/GenericPermissionTest.php +++ b/tests/Permission/GenericPermissionTest.php @@ -13,6 +13,9 @@ use Zend\Permissions\Acl\Resource\GenericResource; use Zend\Permissions\Acl\Role\GenericRole; +/** + * Class GenericPermissionTest + */ class GenericPermissionTest extends AclManTestCase { protected $permission; @@ -24,9 +27,9 @@ public function testConstruct() $options = [ 'resource' => $resource2, - 'role' => $role1, - 'allow' => true, - 'assert' => 'test' + 'role' => $role1, + 'allow' => true, + 'assert' => 'test' ]; $this->permission = new GenericPermission($options); @@ -37,10 +40,10 @@ public function testConstruct() $this->assertSame('test', $this->permission->getAssertion()); $options = [ - 'resource' => 'resource2', - 'role' => 'role1', - 'allow' => false, - 'assert' => 'test', + 'resource' => 'resource2', + 'role' => 'role1', + 'allow' => false, + 'assert' => 'test', 'privilege' => 'add' ]; @@ -67,11 +70,12 @@ public function testSetterRoleResource() $this->assertSame('role1', $this->permission->getRoleId()); $this->assertSame('resource2', $this->permission->getResourceId()); } + public function testSetterPrivilege() { $this->permission = new GenericPermission(); - $this->permission ->setPrivilege('edit'); - $this->assertSame('edit', $this->permission ->getPrivilege()); + $this->permission->setPrivilege('edit'); + $this->assertSame('edit', $this->permission->getPrivilege()); } } diff --git a/tests/Role/RoleAwareTraitTest.php b/tests/Role/RoleAwareTraitTest.php index 2d80cc9..109b245 100644 --- a/tests/Role/RoleAwareTraitTest.php +++ b/tests/Role/RoleAwareTraitTest.php @@ -10,6 +10,9 @@ use AclManTest\AclManTestCase; +/** + * Class RoleAwareTraitTest + */ class RoleAwareTraitTest extends AclManTestCase { /** diff --git a/tests/Service/ServiceAbstractTest.php b/tests/Service/ServiceAbstractTest.php index c9d0c8b..1375749 100644 --- a/tests/Service/ServiceAbstractTest.php +++ b/tests/Service/ServiceAbstractTest.php @@ -15,6 +15,9 @@ use AclManTest\Assertion\TestAsset\MockAssertionPluginManager; use Zend\Permissions\Acl\Acl; +/** + * Class ServiceAbstractTest + */ class ServiceAbstractTest extends AclManTestCase { /** @@ -31,9 +34,9 @@ public function setUp() public function testServiceAbstractInit() { - $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') - ->disableOriginalConstructor() - ->getMock(); + $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') + ->disableOriginalConstructor() + ->getMock(); $mockStorage->expects($this->any()) ->method('getRoles') @@ -44,7 +47,7 @@ public function testServiceAbstractInit() $this->assertEmpty($this->service->getRoles()); - $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') + $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') ->disableOriginalConstructor() ->getMock(); @@ -84,7 +87,7 @@ public function testServiceAbstractAllowNotFoundResource() public function testLoadResourceNotFound() { - $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') + $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') ->disableOriginalConstructor() ->setMethods(['hasResource', 'getPermissions']) ->getMock(); @@ -109,7 +112,7 @@ public function testLoadResourceAllow() { $this->service->addRole('role1'); - $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') + $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') ->disableOriginalConstructor() ->setMethods(['hasResource', 'getPermissions', 'hasRole']) ->getMock(); @@ -118,7 +121,7 @@ public function testLoadResourceAllow() ->method('hasResource') ->will($this->returnValue(true)); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -145,11 +148,7 @@ public function testLoadResourceAllow() $mockStorage->expects($this->any()) ->method('getPermissions') - ->will($this->returnValue([ - $permission - ] - ) - ); + ->will($this->returnValue([$permission])); $this->service->setStorage($mockStorage); @@ -163,7 +162,7 @@ public function testLoadResourceDeny() { $this->service->addRole('role1'); - $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') + $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') ->disableOriginalConstructor() ->setMethods(['hasResource', 'getPermissions', 'hasRole']) ->getMock(); @@ -172,7 +171,7 @@ public function testLoadResourceDeny() ->method('hasResource') ->will($this->returnValue(true)); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -199,11 +198,7 @@ public function testLoadResourceDeny() $mockStorage->expects($this->any()) ->method('getPermissions') - ->will($this->returnValue([ - $permission - ] - ) - ); + ->will($this->returnValue([$permission])); $this->service->setStorage($mockStorage); @@ -220,7 +215,7 @@ public function testLoadResourceAssert() $pluginManager = new MockAssertionPluginManager(); $pluginManager->setService('testAssert', new MockAssertion1()); - $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') + $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') ->disableOriginalConstructor() ->setMethods(['hasResource', 'getPermissions', 'hasRole']) ->getMock(); @@ -229,7 +224,7 @@ public function testLoadResourceAssert() ->method('hasResource') ->will($this->returnValue(true)); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -256,7 +251,9 @@ public function testLoadResourceAssert() $mockStorage->expects($this->any()) ->method('getPermissions') - ->will($this->returnValue([ + ->will( + $this->returnValue( + [ $permission ] ) @@ -281,7 +278,7 @@ public function testIsAllowed() $this->service->addRole('role1'); $this->service->addRole('role2'); - $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') + $mockStorage = $this->getMockBuilder('AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter') ->disableOriginalConstructor() ->setMethods(['hasResource', 'getPermissions', 'hasRole']) ->getMock(); @@ -290,7 +287,7 @@ public function testIsAllowed() ->method('hasResource') ->will($this->returnValue(true)); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -317,7 +314,9 @@ public function testIsAllowed() $mockStorage->expects($this->any()) ->method('getPermissions') - ->will($this->returnValue([ + ->will( + $this->returnValue( + [ $permission ] ) diff --git a/tests/Service/ServiceFactoryTest.php b/tests/Service/ServiceFactoryTest.php index 1486ad3..01b91b3 100644 --- a/tests/Service/ServiceFactoryTest.php +++ b/tests/Service/ServiceFactoryTest.php @@ -8,10 +8,14 @@ */ namespace AclManTest\Service; +use AclMan\Service\ServiceFactory; use AclManTest\AclManTestCase; use Zend\Mvc\Service\ServiceManagerConfig; use Zend\ServiceManager; +/** + * Class ServiceFactoryTest + */ class ServiceFactoryTest extends AclManTestCase { /** @@ -21,7 +25,6 @@ class ServiceFactoryTest extends AclManTestCase public function setUp() { - $config = [ 'alcManServices' => [ 'AclService' => [ @@ -32,25 +35,55 @@ public function setUp() 'AclService1' => [], ], ]; - $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig(array( - 'abstract_factories' => array( + new ServiceManagerConfig( + [ + 'abstract_factories' => [ 'AclMan\Service\ServiceFactory', - ), - ) + ], + ] ) ); $this->serviceManager->setService('Config', $config); - $adapter = $this->getMockBuilder('AclMan\Storage\StorageInterface')->getMock(); $this->serviceManager->setService('ArrayStorage1', $adapter); - $pluginManager = $this->getMockBuilder('AclMan\Assertion\AssertionPluginManager')->getMock(); $this->serviceManager->setService('PluginManager', $pluginManager); } + public function testCreateServiceShouldThrowServiceNotCreatedExceptionWhenStorageIsInvalid() + { + $sm = new ServiceManager\ServiceManager( + new ServiceManagerConfig( + [ + 'abstract_factories' => [ + 'AclMan\Service\ServiceFactory', + ], + ] + ) + ); + $sm->setService( + 'Config', + [ + 'alcManServices' => [ + 'AclService' => [ + 'storage' => 'InvalidStorage', + 'pluginManager' => 'PluginManager', + 'allowNotFoundResource' => true + ], + 'AclService1' => [], + ] + ] + ); + $sm->setService('PluginManager', $this->getMockBuilder('AclMan\Assertion\AssertionPluginManager')->getMock()); + $sm->setService('InvalidStorage', $this->getMockBuilder('\ArrayObject')->getMock()); + $sf = new ServiceFactory(); + $this->assertTrue($sf->canCreateServiceWithName($sm, null, 'AclService')); + $this->setExpectedException('\AclMan\Exception\ServiceNotCreatedException'); + $sf->createServiceWithName($sm, null, 'AclService'); + } + public function testHasService() { $serviceLocator = $this->serviceManager; @@ -61,26 +94,28 @@ public function testHasService() public function testHasServiceWithoutConfig() { $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig(array( - 'abstract_factories' => array( + new ServiceManagerConfig( + [ + 'abstract_factories' => [ 'AclMan\Service\ServiceFactory', - ), - ) + ], + ] ) ); $this->assertFalse($this->serviceManager->has('AclService')); $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig(array( - 'abstract_factories' => array( + new ServiceManagerConfig( + [ + 'abstract_factories' => [ 'AclMan\Service\ServiceFactory', - ), - ) + ], + ] ) ); - $this->serviceManager->setService('Config', array()); + $this->serviceManager->setService('Config', []); $this->assertFalse($this->serviceManager->has('AclService')); } diff --git a/tests/Storage/Adapter/ArrayAdapter/ArrayAdapterAbstractServiceFactoryTest.php b/tests/Storage/Adapter/ArrayAdapter/ArrayAdapterAbstractServiceFactoryTest.php index 863c055..74f0da9 100644 --- a/tests/Storage/Adapter/ArrayAdapter/ArrayAdapterAbstractServiceFactoryTest.php +++ b/tests/Storage/Adapter/ArrayAdapter/ArrayAdapterAbstractServiceFactoryTest.php @@ -13,6 +13,9 @@ use Zend\Mvc\Service\ServiceManagerConfig; use Zend\ServiceManager; +/** + * Class ArrayAdapterAbstractServiceFactoryTest + */ class ArrayAdapterAbstractServiceFactoryTest extends AclManTestCase { /** @@ -35,12 +38,11 @@ public function setUp() ]; $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig(array( - 'abstract_factories' => array( - 'AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapterAbstractServiceFactory', - ), - ) - ) + new ServiceManagerConfig([ + 'abstract_factories' => [ + 'AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapterAbstractServiceFactory', + ], + ]) ); $this->serviceManager->setService('Config', $config); @@ -57,27 +59,22 @@ public function testHasService() public function testHasServiceWithoutConfig() { $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig(array( - 'abstract_factories' => array( - 'AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapterAbstractServiceFactory', - ), - ) - ) + new ServiceManagerConfig([ + 'abstract_factories' => [ + 'AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapterAbstractServiceFactory', + ], + ]) ); - $this->assertFalse($this->serviceManager->has('ArrayStorage1')); $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig(array( - 'abstract_factories' => array( - 'AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapterAbstractServiceFactory', - ), - ) - ) + new ServiceManagerConfig([ + 'abstract_factories' => [ + 'AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapterAbstractServiceFactory', + ], + ]) ); - - $this->serviceManager->setService('Config', array()); - + $this->serviceManager->setService('Config', []); $this->assertFalse($this->serviceManager->has('ArrayStorage1')); } diff --git a/tests/Storage/Adapter/ArrayAdapter/ArrayAdapterTest.php b/tests/Storage/Adapter/ArrayAdapter/ArrayAdapterTest.php index 74e9b2c..7816cdc 100644 --- a/tests/Storage/Adapter/ArrayAdapter/ArrayAdapterTest.php +++ b/tests/Storage/Adapter/ArrayAdapter/ArrayAdapterTest.php @@ -8,12 +8,12 @@ */ namespace AclManTest\Storage\Adapter\ArrayAdapter; -use AclMan\Permission\GenericPermission; use AclMan\Storage\Adapter\ArrayAdapter\ArrayAdapter; use AclManTest\AclManTestCase; -use Zend\Permissions\Acl\Resource\GenericResource; -use Zend\Permissions\Acl\Role\GenericRole; +/** + * Class ArrayAdapterTest + */ class ArrayAdapterTest extends AclManTestCase { /** @@ -22,43 +22,43 @@ class ArrayAdapterTest extends AclManTestCase protected $adapter; protected $config = [ - 'roles' => [ - 'role1' => [ - 'resources' => [ - 'resource1' => [ - [ - 'assert' => 'test', - 'allow' => true, - 'privilege' => 'view' - ], - [ - 'assert' => 'test', - 'allow' => true, - 'privilege' => 'add' - ] - ] - ] - ], - 'role2' => [ - 'parents' => [ - 'role1' - ], - 'resources' => [ - 'resource2' => [ - [ - 'assert' => 'test', - 'allow' => true, - 'privilege' => 'view' - ], - [ - 'assert' => 'test', - 'allow' => true, - 'privilege' => 'add' - ] - ] - ] - ], - ] + 'roles' => [ + 'role1' => [ + 'resources' => [ + 'resource1' => [ + [ + 'assert' => 'test', + 'allow' => true, + 'privilege' => 'view' + ], + [ + 'assert' => 'test', + 'allow' => true, + 'privilege' => 'add' + ] + ] + ] + ], + 'role2' => [ + 'parents' => [ + 'role1' + ], + 'resources' => [ + 'resource2' => [ + [ + 'assert' => 'test', + 'allow' => true, + 'privilege' => 'view' + ], + [ + 'assert' => 'test', + 'allow' => true, + 'privilege' => 'add' + ] + ] + ] + ], + ] ]; public function setUp() @@ -67,7 +67,7 @@ public function setUp() } /** - * @expectedException \AclMan\Role\Exception\InvalidParameterException + * @expectedException \AclMan\Exception\InvalidParameterException */ public function testHasRolesException() { @@ -101,7 +101,7 @@ public function testAddRoleParents() /** * @depends testHasRoles - * @expectedException \AclMan\Storage\Exception\RoleAlreadyExistException + * @expectedException \AclMan\Exception\RoleAlreadyExistException */ public function testAddRoleException() { @@ -110,7 +110,7 @@ public function testAddRoleException() } /** - * @expectedException \AclMan\Role\Exception\InvalidParameterException + * @expectedException \AclMan\Exception\InvalidParameterException */ public function testAddRoleException2() { @@ -136,9 +136,9 @@ public function testAddRoles() */ public function testGetRoles() { - $this->assertCount(0, $this->adapter->getRoles()); + $this->assertCount(0, $this->adapter->getRoles()); $this->adapter->addRoles(['role1']); - $this->assertCount(1, $this->adapter->getRoles()); + $this->assertCount(1, $this->adapter->getRoles()); } /** @@ -147,14 +147,14 @@ public function testGetRoles() public function testGetParentRoles() { $this->adapter->addRoles(['role1']); - $this->assertCount(0, $this->adapter->getParentRoles('role1')); + $this->assertCount(0, $this->adapter->getParentRoles('role1')); $this->adapter->addRoles([['role' => 'role2', 'parents' => ['role1']]]); - $this->assertCount(1, $this->adapter->getParentRoles('role2')); + $this->assertCount(1, $this->adapter->getParentRoles('role2')); } /** - * @expectedException \AclMan\Storage\Exception\RoleNotExistException + * @expectedException \AclMan\Exception\RoleNotExistException */ public function testGetParentRolesException() { @@ -172,11 +172,11 @@ public function testAddParentRoles() $this->assertTrue($this->adapter->addParentRoles('role3', ['role1', 'role2'])); - $this->assertCount(2, $this->adapter->getParentRoles('role3')); + $this->assertCount(2, $this->adapter->getParentRoles('role3')); } /** - * @expectedException \AclMan\Storage\Exception\RoleNotExistException + * @expectedException \AclMan\Exception\RoleNotExistException */ public function testAddParentRolesException1() { @@ -185,7 +185,7 @@ public function testAddParentRolesException1() /** * @depends testAddRole - * @expectedException \AclMan\Storage\Exception\RoleNotExistException + * @expectedException \AclMan\Exception\RoleNotExistException */ public function testAddParentRolesException2() { @@ -209,7 +209,7 @@ public function testAddResource() /** * @depends testAddResource - * @expectedException \AclMan\Storage\Exception\ResourceAlreadyExistException + * @expectedException \AclMan\Exception\ResourceAlreadyExistException */ public function testAddResourceException() { @@ -219,7 +219,7 @@ public function testAddResourceException() /** * @depends testAddResource - * @expectedException \AclMan\Resource\Exception\InvalidParameterException + * @expectedException \AclMan\Exception\InvalidParameterException */ public function testAddResourceException2() { @@ -254,7 +254,7 @@ public function testAddPermission() $this->adapter->addRoles(['role1']); $this->adapter->addResource('resource1'); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -291,7 +291,7 @@ public function testAddPermissionNoRoleNoResource() $this->adapter->addRoles(['role1']); $this->adapter->addResource('resource1'); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -321,13 +321,13 @@ public function testAddPermissionNoRoleNoResource() /** * @depends testAddPermission - * @expectedException \AclMan\Storage\Exception\ResourceNotExistException + * @expectedException \AclMan\Exception\ResourceNotExistException */ public function testAddPermissionException1() { $this->adapter->addRoles(['role1']); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -358,11 +358,11 @@ public function testAddPermissionException1() /** * @depends testAddPermission - * @expectedException \AclMan\Storage\Exception\RoleNotExistException + * @expectedException \AclMan\Exception\RoleNotExistException */ public function testAddPermissionException2() { - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -393,7 +393,7 @@ public function testAddPermissionException2() /** * @depends testAddPermission - * @expectedException \AclMan\Permission\Exception\InvalidParameterException + * @expectedException \AclMan\Exception\InvalidParameterException */ public function testAddPermissionException3() { @@ -413,7 +413,7 @@ public function testAddPermissions() $permissions = []; - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -440,7 +440,7 @@ public function testAddPermissions() array_push($permissions, $permission); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -480,7 +480,7 @@ public function testGetPermission() $this->adapter->addResource('resource1'); $this->adapter->addResource('resource2'); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); @@ -510,7 +510,7 @@ public function testGetPermission() $this->assertCount(1, $this->adapter->getPermissions('role1', 'resource1')); - $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') + $permission = $this->getMockBuilder('AclMan\Permission\GenericPermission') ->disableOriginalConstructor() ->setMethods(['getAssertion', 'isAllow', 'getPrivilege', 'getResourceId', 'getRoleId']) ->getMock(); diff --git a/tests/Storage/StorageAwareTraitTest.php b/tests/Storage/StorageAwareTraitTest.php index bad3911..d0d78c4 100644 --- a/tests/Storage/StorageAwareTraitTest.php +++ b/tests/Storage/StorageAwareTraitTest.php @@ -10,6 +10,9 @@ use AclManTest\AclManTestCase; +/** + * Class StorageAwareTraitTest + */ class StorageAwareTraitTest extends AclManTestCase { protected $traitObject; @@ -25,6 +28,6 @@ public function testStorageAwareTrait() $this->getMockBuilder('AclMan\Storage\StorageInterface') ->getMock() ); - $this->assertInstanceOf('AclMan\Storage\StorageInterface', $this->traitObject->getStorage()); + $this->assertInstanceOf('AclMan\Storage\StorageInterface', $this->traitObject->getStorage()); } } diff --git a/tests/Storage/StorageFactoryTest.php b/tests/Storage/StorageFactoryTest.php index eea79b5..79ba00a 100644 --- a/tests/Storage/StorageFactoryTest.php +++ b/tests/Storage/StorageFactoryTest.php @@ -12,6 +12,9 @@ use Zend\Mvc\Service\ServiceManagerConfig; use Zend\ServiceManager; +/** + * Class StorageFactoryTest + */ class StorageFactoryTest extends AclManTestCase { /** @@ -53,14 +56,12 @@ public function setUp() ]; $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig(array( - 'abstract_factories' => array( - 'AclMan\Storage\StorageFactory', - ), - ) - ) + new ServiceManagerConfig([ + 'abstract_factories' => [ + 'AclMan\Storage\StorageFactory', + ], + ]) ); - $this->serviceManager->setService('Config', $config); } @@ -81,26 +82,24 @@ public function testGetService() public function testHasServiceWithoutConfig() { $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig(array( - 'abstract_factories' => array( - 'AclMan\Storage\StorageFactory', - ), - ) - ) + new ServiceManagerConfig([ + 'abstract_factories' => [ + 'AclMan\Storage\StorageFactory', + ], + ]) ); $this->assertFalse($this->serviceManager->has('AclStorage')); $this->serviceManager = new ServiceManager\ServiceManager( - new ServiceManagerConfig(array( - 'abstract_factories' => array( - 'AclMan\Storage\StorageFactory', - ), - ) - ) + new ServiceManagerConfig([ + 'abstract_factories' => [ + 'AclMan\Storage\StorageFactory', + ], + ]) ); - $this->serviceManager->setService('Config', array()); + $this->serviceManager->setService('Config', []); $this->assertFalse($this->serviceManager->has('AclStorage')); } diff --git a/tests/Storage/TestAsset/MockAdapter.php b/tests/Storage/TestAsset/MockAdapter.php index 631c0bb..836c81c 100644 --- a/tests/Storage/TestAsset/MockAdapter.php +++ b/tests/Storage/TestAsset/MockAdapter.php @@ -13,97 +13,89 @@ use Zend\Permissions\Acl\Resource\ResourceInterface; use Zend\Permissions\Acl\Role\RoleInterface; +/** + * Class MockAdapter + */ class MockAdapter implements StorageInterface { /** - * @param $role - * @param array $parents - * @return bool + * {@inheritdoc} */ public function addParentRoles($role, array $parents) { - // TODO: Implement addParentRoles() method. + // TODO: implement addParentRoles() method. } /** - * @param $role - * @return array + * {@inheritdoc} */ public function getParentRoles($role) { - // TODO: Implement getParentRoles() method. + // TODO: implement getParentRoles() method. } /** - * @return array + * {@inheritdoc} */ public function getRoles() { - // TODO: Implement getRoles() method. + // TODO: implement getRoles() method. } /** - * @param RoleInterface $role - * @param array $parents - * @return bool + * {@inheritdoc} */ public function addRole($role, array $parents = []) { - // TODO: Implement addRole() method. + // TODO: implement addRole() method. } /** - * @param RoleInterface $role - * @return bool + * {@inheritdoc} */ public function hasRole($role) { - // TODO: Implement hasRole() method. + // TODO: implement hasRole() method. } /** - * @return array + * {@inheritdoc} */ public function getResources() { - // TODO: Implement getResources() method. + // TODO: implement getResources() method. } /** - * @param ResourceInterface $resource - * @return bool + * {@inheritdoc} */ public function addResource($resource) { - // TODO: Implement addResource() method. + // TODO: implement addResource() method. } /** - * @param ResourceInterface $resource - * @return bool + * {@inheritdoc} */ public function hasResource($resource) { - // TODO: Implement hasResource() method. + // TODO: implement hasResource() method. } /** - * @param null $role - * @param null $resource - * @return array + * {@inheritdoc} */ public function getPermissions($role = null, $resource = null) { - // TODO: Implement getPermissions() method. + // TODO: implement getPermissions() method. } /** - * @param PermissionInterface $permission - * @return bool + * {@inheritdoc} */ public function addPermission($permission) { - // TODO: Implement addPermission() method. + // TODO: implement addPermission() method. } }