[ 'LmcRbacMvc\Guard\RouteGuard' => [ 'admin/*' => 'role1' ], 'LmcRbacMvc\Guard\RoutePermissionsGuard' => [ 'admin/post' => 'post.manage' ], 'LmcRbacMvc\Guard\ControllerGuard' => [[ 'controller' => 'MyController', 'actions' => ['index', 'edit'], 'roles' => ['role'] ]], 'LmcRbacMvc\Guard\ControllerPermissionsGuard' => [[ 'controller' => 'PostController', 'actions' => ['index', 'edit'], 'permissions' => ['post.read'] ]] ] ]); $serviceManager = new ServiceManager(); $pluginManager = new GuardPluginManager($serviceManager); $serviceManager->setService('LmcRbacMvc\Options\ModuleOptions', $moduleOptions); $serviceManager->setService('LmcRbacMvc\Guard\GuardPluginManager', $pluginManager); $serviceManager->setService( 'LmcRbacMvc\Service\RoleService', $this->getMockBuilder('LmcRbacMvc\Service\RoleService')->disableOriginalConstructor()->getMock() ); $serviceManager->setService( 'LmcRbacMvc\Service\AuthorizationService', $this->getMockBuilder('LmcRbacMvc\Service\AuthorizationServiceInterface')->disableOriginalConstructor()->getMock() ); $factory = new GuardsFactory(); $guards = $factory->createService($serviceManager); $this->assertIsArray($guards); $this->assertCount(4, $guards); $this->assertInstanceOf('LmcRbacMvc\Guard\RouteGuard', $guards[0]); $this->assertInstanceOf('LmcRbacMvc\Guard\RoutePermissionsGuard', $guards[1]); $this->assertInstanceOf('LmcRbacMvc\Guard\ControllerGuard', $guards[2]); $this->assertInstanceOf('LmcRbacMvc\Guard\ControllerPermissionsGuard', $guards[3]); } public function testReturnArrayIfNoConfig() { $moduleOptions = new ModuleOptions([ 'guards' => [] ]); $serviceManager = new ServiceManager(); $pluginManager = new GuardPluginManager($serviceManager); $serviceManager->setService('LmcRbacMvc\Options\ModuleOptions', $moduleOptions); $factory = new GuardsFactory(); $guards = $factory->createService($serviceManager); $this->assertIsArray($guards); $this->assertEmpty($guards); } }