public static getServiceManager ( array $config = null ) : Zend\ServiceManager\ServiceManager | ||
$config | array | |
Résultat | Zend\ServiceManager\ServiceManager |
public function testHelperIsRegistered() { $serviceManager = ServiceManagerFactory::getServiceManager(); $config = $serviceManager->get('Config'); $this->assertArrayHasKey('view_helpers', $config); $viewHelpersConfig = $config['view_helpers']; $this->assertEquals('ZfcRbac\\View\\Helper\\IsGranted', $viewHelpersConfig['aliases']['isGranted']); $this->assertEquals('ZfcRbac\\Factory\\IsGrantedViewHelperFactory', $viewHelpersConfig['factories']['ZfcRbac\\View\\Helper\\IsGranted']); }
public function testAssertModuleDefaultOptions() { /** @var \ZfcRbac\Options\ModuleOptions $moduleOptions */ $moduleOptions = ServiceManagerFactory::getServiceManager()->get('ZfcRbac\\Options\\ModuleOptions'); $this->assertEquals('ZfcRbac\\Identity\\AuthenticationIdentityProvider', $moduleOptions->getIdentityProvider()); $this->assertEquals('guest', $moduleOptions->getGuestRole()); $this->assertEquals('allow', $moduleOptions->getProtectionPolicy()); $this->assertInternalType('array', $moduleOptions->getGuards()); $this->assertInternalType('array', $moduleOptions->getRoleProvider()); $this->assertInternalType('array', $moduleOptions->getAssertionMap()); $this->assertInstanceOf('ZfcRbac\\Options\\UnauthorizedStrategyOptions', $moduleOptions->getUnauthorizedStrategy()); $this->assertInstanceOf('ZfcRbac\\Options\\RedirectStrategyOptions', $moduleOptions->getRedirectStrategy()); }
public function testDelegatorThrowExceptionWhenBadInterface() { $serviceManager = ServiceManagerFactory::getServiceManager(); $serviceManager->setAllowOverride(true); $authorizationService = $this->getMock('ZfcRbac\\Service\\AuthorizationService', [], [], '', false); $serviceManager->setService('ZfcRbac\\Service\\AuthorizationService', $authorizationService); $serviceManager->setAllowOverride(false); $serviceManager->setFactory('ZfcRbacTest\\AuthorizationAware', function () { return new \StdClass(); }); $serviceManager->addDelegator('ZfcRbacTest\\AuthorizationAware', 'ZfcRbac\\Factory\\AuthorizationServiceDelegatorFactory'); $this->setExpectedException('ZfcRbac\\Exception\\RuntimeException', 'The service ZfcRbacTest\\AuthorizationAware must implement AuthorizationServiceAwareInterface.'); $serviceManager->get('ZfcRbacTest\\AuthorizationAware'); }
public function testThrowExceptionIfAskedRoleIsNotFound() { $this->serviceManager = ServiceManagerFactory::getServiceManager(); $objectManager = $this->getObjectManager(); $objectRepository = $objectManager->getRepository('ZfcRbacTest\\Asset\\FlatRole'); $objectRepositoryRoleProvider = new ObjectRepositoryRoleProvider($objectRepository, 'name'); $this->setExpectedException('ZfcRbac\\Exception\\RoleNotFoundException', 'Some roles were asked but could not be loaded from database: guest, admin'); $objectRepositoryRoleProvider->getRoles(['guest', 'admin']); }
public function testDelegatorThrowExceptionWhenBadInterface() { $serviceManager = ServiceManagerFactory::getServiceManager(); $serviceManager->setAllowOverride(true); $authorizationService = $this->getMock('ZfcRbac\\Service\\AuthorizationService', [], [], '', false); $serviceManager->setService('ZfcRbac\\Service\\AuthorizationService', $authorizationService); $serviceManager->setAllowOverride(false); $serviceManager->setFactory('ZfcRbacTest\\AuthorizationAware', function () { return new \StdClass(); }); $serviceManager->addDelegator('ZfcRbacTest\\AuthorizationAware', 'ZfcRbac\\Factory\\AuthorizationServiceDelegatorFactory'); $thrown = false; try { $serviceManager->get('ZfcRbacTest\\AuthorizationAware'); } catch (\Exception $e) { $thrown = true; $this->assertStringEndsWith('The service ZfcRbacTest\\AuthorizationAware must implement AuthorizationServiceAwareInterface.', $e->getMessage()); if ($e->getPrevious()) { $this->assertInstanceOf('ZfcRbac\\Exception\\RuntimeException', $e->getPrevious()); } } $this->assertTrue($thrown); }