当前位置: 首页>>代码示例>>PHP>>正文


PHP SecurityContextInterface::expects方法代码示例

本文整理汇总了PHP中Symfony\Component\Security\Core\SecurityContextInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP SecurityContextInterface::expects方法的具体用法?PHP SecurityContextInterface::expects怎么用?PHP SecurityContextInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Security\Core\SecurityContextInterface的用法示例。


在下文中一共展示了SecurityContextInterface::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     /* @var $conn Connection */
     $conn = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $conn->expects($this->any())->method('getDatabase')->will($this->returnValue('myDatabase'));
     /* @var $platform AbstractPlatform */
     $platform = $this->getMockForAbstractClass('Doctrine\\DBAL\\Platforms\\AbstractPlatform');
     $conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     /* @var $stmt Statement */
     $stmt = $this->getMockForAbstractClass('Kunstmaan\\AdminBundle\\Tests\\Mocks\\StatementMock');
     $conn->expects($this->any())->method('executeQuery')->will($this->returnValue($stmt));
     $this->em->expects($this->any())->method('getConnection')->will($this->returnValue($conn));
     /* @var $conf Configuration */
     $conf = $this->getMockBuilder('Doctrine\\ORM\\Configuration')->disableOriginalConstructor()->getMock();
     /* @var $strat QuoteStrategy */
     $strat = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\QuoteStrategy')->disableOriginalConstructor()->getMock();
     $strat->expects($this->any())->method('getTableName')->will($this->returnValue('rootTable'));
     $conf->expects($this->any())->method('getQuoteStrategy')->will($this->returnValue($strat));
     $conf->expects($this->any())->method('getDefaultQueryHints')->willReturn(array());
     $conf->expects($this->any())->method('isSecondLevelCacheEnabled')->willReturn(false);
     $this->em->expects($this->any())->method('getConfiguration')->will($this->returnValue($conf));
     /* @var $meta ClassMetadata */
     $meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($meta));
     $this->sc = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\SecurityContextInterface')->getMock();
     $this->token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')->getMock();
     $this->sc->expects($this->any())->method('getToken')->will($this->returnValue($this->token));
     $this->rh = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Role\\RoleHierarchyInterface')->getMock();
     $this->object = new AclHelper($this->em, $this->sc, $this->rh);
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:35,代码来源:AclHelperTest.php

示例2: testBuild

 public function testBuild()
 {
     $organization = new Organization();
     $type = 'history';
     $userId = 1;
     $user = $this->getMockBuilder('stdClass')->setMethods(array('getId'))->getMock();
     $user->expects($this->once())->method('getId')->will($this->returnValue($userId));
     $token = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\Authentication\\Token\\UsernamePasswordOrganizationToken')->disableOriginalConstructor()->getMock();
     $token->expects($this->once())->method('getUser')->will($this->returnValue($user));
     $token->expects($this->once())->method('getOrganizationContext')->will($this->returnValue($organization));
     $this->securityContext->expects($this->atLeastOnce())->method('getToken')->will($this->returnValue($token));
     $item = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationItemInterface');
     $this->factory->expects($this->once())->method('createItem')->with($type, array())->will($this->returnValue($item));
     $repository = $this->getMockBuilder('Oro\\Bundle\\NavigationBundle\\Entity\\Repository\\HistoryItemRepository')->disableOriginalConstructor()->getMock();
     $items = array(array('id' => 1, 'title' => 'test1', 'url' => '/'), array('id' => 2, 'title' => 'test2', 'url' => '/home'));
     $repository->expects($this->once())->method('getNavigationItems')->with($userId, $organization, $type)->will($this->returnValue($items));
     $this->em->expects($this->once())->method('getRepository')->with(get_class($item))->will($this->returnValue($repository));
     $menu = $this->getMockBuilder('Knp\\Menu\\MenuItem')->disableOriginalConstructor()->getMock();
     $childMock = $this->getMock('Knp\\Menu\\ItemInterface');
     $childMock2 = clone $childMock;
     $children = array($childMock, $childMock2);
     $matcher = $this->getMock('\\Knp\\Menu\\Matcher\\Matcher');
     $matcher->expects($this->once())->method('isCurrent')->will($this->returnValue(true));
     $this->builder->setMatcher($matcher);
     $menu->expects($this->exactly(2))->method('addChild');
     $menu->expects($this->once())->method('setExtra')->with('type', $type);
     $menu->expects($this->once())->method('getChildren')->will($this->returnValue($children));
     $menu->expects($this->once())->method('removeChild');
     $n = rand(1, 10);
     $configMock = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $configMock->expects($this->once())->method('get')->with($this->equalTo('oro_navigation.maxItems'))->will($this->returnValue($n));
     $this->manipulator->expects($this->once())->method('slice')->with($menu, 0, $n);
     $this->builder->setOptions($configMock);
     $this->builder->build($menu, array(), $type);
 }
开发者ID:Maksold,项目名称:platform,代码行数:35,代码来源:NavigationHistoryBuilderTest.php

示例3: setUp

 public function setUp()
 {
     $dbManager = $this->db('PHPCR');
     $dbManager->loadFixtures(array('Symfony\\Cmf\\Bundle\\CoreBundle\\Tests\\Resources\\DataFixture\\LoadHierarchyRouteData'));
     $this->pwc = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $this->pwc->expects($this->any())->method('isGranted')->will($this->returnValue(true));
     $this->helper = new CmfHelper($this->pwc, $dbManager->getRegistry(), 'default');
 }
开发者ID:viral810,项目名称:ngSimpleCMS,代码行数:8,代码来源:CmfHelperHierarchyTest.php

示例4: setUp

 public function setUp()
 {
     $this->securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $this->configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $token = $this->getMockForAbstractClass('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->user = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\User')->disableOriginalConstructor()->getMock();
     $token->expects($this->any())->method('getUser')->will($this->returnValue($this->user));
     $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $this->provider = new VariablesProvider($this->securityContext, $this->configProvider);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:10,代码来源:VariableProviderTest.php

示例5: testIsGrantedWithException

 public function testIsGrantedWithException()
 {
     $this->setExpectedException('RuntimeException', 'Something is wrong');
     $this->admin->expects($this->any())->method('getCode')->will($this->returnValue('foo.bar'));
     $this->securityContext->expects($this->any())->method('isGranted')->will($this->returnCallback(function (array $attributes, $object) {
         throw new \RuntimeException('Something is wrong');
     }));
     $handler = $this->getRoleSecurityHandler(array('ROLE_BATMAN'));
     $handler->isGranted($this->admin, 'BAZ');
 }
开发者ID:jerome-fix,项目名称:SonataAdminBundle,代码行数:10,代码来源:RoleSecurityHandlerTest.php

示例6: setUp

 protected function setUp()
 {
     $this->factory = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\Builder\\ItemFactory');
     $this->securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $user = new User();
     $user->setEmail('some@email.com');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $this->item = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationHistoryItem');
     $this->serializedTitle = json_encode(array('titleTemplate' => 'Test title template'));
 }
开发者ID:Maksold,项目名称:platform,代码行数:12,代码来源:ResponseHistoryListenerTest.php

示例7: setUp

 /**
  * setup mocks
  */
 protected function setUp()
 {
     $this->loader = $this->getMock('\\Twig_Loader_String');
     $this->securityPolicy = $this->getMockBuilder('\\Twig_Sandbox_SecurityPolicy')->disableOriginalConstructor()->getMock();
     $this->sandbox = $this->getMockBuilder('\\Twig_Extension_Sandbox')->disableOriginalConstructor()->getMock();
     $this->sandbox->expects($this->once())->method('getName')->will($this->returnValue('sandbox'));
     $this->sandbox->expects($this->once())->method('getSecurityPolicy')->will($this->returnValue($this->securityPolicy));
     $this->securityContext = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $token = $this->getMockForAbstractClass('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->user = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\User')->disableOriginalConstructor()->getMock();
     $token->expects($this->any())->method('getUser')->will($this->returnValue($this->user));
     $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $this->configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $this->cache = $this->getMockBuilder('Doctrine\\Common\\Cache\\Cache')->disableOriginalConstructor()->getMock();
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:18,代码来源:EmailRendererTest.php

示例8: testLoadWithAlternativeDocumentManager

 /**
  * Test using the block loader with two different document managers.
  */
 public function testLoadWithAlternativeDocumentManager()
 {
     $absoluteBlockPath = '/some/absolute/path';
     $block = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface');
     $block->expects($this->any())->method('getName')->will($this->returnValue('the-block'));
     $altBlock = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface');
     $altBlock->expects($this->any())->method('getName')->will($this->returnValue('alt-block'));
     $this->dmMock->expects($this->once())->method('find')->with($this->equalTo(null), $this->equalTo($absoluteBlockPath))->will($this->returnValue($block));
     $altDmMock = $this->getMockBuilder('Doctrine\\ODM\\PHPCR\\DocumentManager')->disableOriginalConstructor()->getMock();
     $altDmMock->expects($this->once())->method('find')->with($this->equalTo(null), $this->equalTo($absoluteBlockPath))->will($this->returnValue($altBlock));
     $this->securityMock->expects($this->at(0))->method('isGranted')->with(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->equalTo($block))->will($this->returnValue(true));
     $this->securityMock->expects($this->at(1))->method('isGranted')->with(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->equalTo($altBlock))->will($this->returnValue(true));
     $registryMock = $this->getMockBuilder('Doctrine\\Bundle\\PHPCRBundle\\ManagerRegistry')->disableOriginalConstructor()->getMock();
     $registryMock->expects($this->at(0))->method('getManager')->with($this->equalTo('themanager'))->will($this->returnValue($this->dmMock));
     $registryMock->expects($this->at(1))->method('getManager')->with($this->equalTo('altmanager'))->will($this->returnValue($altDmMock));
     $blockLoader = new PhpcrBlockLoader($registryMock, $this->securityMock, null, 'emptyblocktype');
     $blockLoader->setManagerName('themanager');
     $foundBlock = $blockLoader->load(array('name' => $absoluteBlockPath));
     $this->assertInstanceOf('Sonata\\BlockBundle\\Model\\BlockInterface', $foundBlock);
     $this->assertEquals('the-block', $foundBlock->getName());
     $blockLoader->setManagerName('altmanager');
     $foundBlock = $blockLoader->load(array('name' => $absoluteBlockPath));
     $this->assertInstanceOf('Sonata\\BlockBundle\\Model\\BlockInterface', $foundBlock);
     $this->assertEquals('alt-block', $foundBlock->getName());
 }
开发者ID:frogriotcom,项目名称:BlockBundle,代码行数:28,代码来源:PhpcrBlockLoaderTest.php

示例9: setUp

 protected function setUp()
 {
     $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $this->object = new UserConfigManager($this->om, $this->settings);
     $this->security = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $this->group1 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group');
     $this->group2 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $user = new User();
     $this->security->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $this->group1->expects($this->any())->method('getId')->will($this->returnValue(2));
     $this->group2->expects($this->any())->method('getId')->will($this->returnValue(3));
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $user->setId(1)->addGroup($this->group1)->addGroup($this->group2);
     $this->object = $this->getMock('Oro\\Bundle\\ConfigBundle\\Config\\UserConfigManager', array('loadStoredSettings'), array($this->om, $this->settings));
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:16,代码来源:UserConfigManagerTest.php

示例10: testRedirect

 /**
  * @dataProvider getUser
  */
 public function testRedirect($granted, $path)
 {
     $default = new Netizen(new Author('kirk'));
     $default->setCredential(new OAuth('1701', 'ufp'));
     $request = new Request();
     $token = new Token('secured_area', 'ufp', '1701');
     $token->setUser($default);
     $this->security->expects($this->atLeast(1))->method('isGranted')->will($this->returnCallback(function ($role) use($granted) {
         return $role == $granted;
     }));
     $this->urlGenerator->expects($this->once())->method('generate')->with($path)->willReturn('ok');
     $response = $this->sut->onAuthenticationSuccess($request, $token);
     $cookie = $response->headers->getCookies()[0];
     $this->assertEquals('oauth_provider', $cookie->getName());
     $this->assertEquals('ufp', $cookie->getValue());
 }
开发者ID:xtrasmal,项目名称:iinano,代码行数:19,代码来源:LandingPageSuccessHandlerTest.php

示例11: setUp

 protected function setUp()
 {
     $repo = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigRepository')->disableOriginalConstructor()->getMock();
     $repo->expects($this->any())->method('loadSettings');
     $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repo));
     $this->object = new UserScopeManager($this->om);
     $this->security = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->security->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $token->expects($this->any())->method('getUser')->will($this->returnValue($this->getUser()));
     $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $this->container->expects($this->any())->method('get')->will($this->returnValueMap([['security.context', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->security]]));
     $this->object = new UserScopeManager($this->om);
     $this->object->setContainer($this->container);
 }
开发者ID:northdakota,项目名称:platform,代码行数:16,代码来源:UserScopeManagerTest.php

示例12: testNoFirewall

 public function testNoFirewall()
 {
     $token = new AnonymousToken('', '');
     $this->sc->expects($this->any())->method('getToken')->will($this->returnValue(null));
     $this->sc->expects($this->never())->method('isGranted');
     $this->adm->expects($this->once())->method('decide')->with($token, array(PublishWorkflowChecker::VIEW_ATTRIBUTE), $this->doc)->will($this->returnValue(true));
     $this->assertTrue($this->pwfc->isGranted(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->doc));
 }
开发者ID:viral810,项目名称:ngSimpleCMS,代码行数:8,代码来源:PublishWorkflowCheckerTest.php

示例13: setUp

 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->conn = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $this->conn->expects($this->any())->method('getDatabase')->will($this->returnValue('myDatabase'));
     /* @var $platform AbstractPlatform */
     $platform = $this->getMockForAbstractClass('Doctrine\\DBAL\\Platforms\\AbstractPlatform');
     $this->conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     $this->em->expects($this->any())->method('getConnection')->will($this->returnValue($this->conn));
     /* @var $meta ClassMetadata */
     $meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($meta));
     $this->sc = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\SecurityContextInterface')->getMock();
     $this->token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')->getMock();
     $this->sc->expects($this->any())->method('getToken')->will($this->returnValue($this->token));
     $this->rh = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Role\\RoleHierarchyInterface')->getMock();
     $this->object = new AclNativeHelper($this->em, $this->sc, $this->rh);
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:22,代码来源:AclNativeHelperTest.php

示例14: setUp

 protected function setUp()
 {
     $repo = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigRepository')->disableOriginalConstructor()->getMock();
     $repo->expects($this->any())->method('loadSettings');
     $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repo));
     $this->object = new UserScopeManager($this->om);
     $this->security = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface');
     $this->group1 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group');
     $this->group2 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $user = new User();
     $this->security->expects($this->any())->method('getToken')->will($this->returnValue($token));
     $this->group1->expects($this->any())->method('getId')->will($this->returnValue(2));
     $this->group2->expects($this->any())->method('getId')->will($this->returnValue(3));
     $token->expects($this->any())->method('getUser')->will($this->returnValue($user));
     $user->setId(1)->addGroup($this->group1)->addGroup($this->group2);
     $this->object = new UserScopeManager($this->om);
 }
开发者ID:nmallare,项目名称:platform,代码行数:19,代码来源:UserScopeManagerTest.php

示例15: testRender

 /**
  * @dataProvider renderDataProvider
  * @param string $widgetUrl
  * @param string $widgetType
  * @param string $expectedWidgetUrl
  */
 public function testRender($widgetUrl, $widgetType, $expectedWidgetUrl)
 {
     $user = $this->getMock('stdClass');
     $token = $this->getMockBuilder('stdClass')->setMethods(array('getUser'))->getMock();
     $token->expects($this->once())->method('getUser')->will($this->returnValue($user));
     $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token));
     $normalStateData = array('cleanUrl' => $widgetUrl, 'type' => $widgetType);
     $normalState = $this->getStateMock(1, $normalStateData);
     $badState = $this->getStateMock(2, null);
     $states = array($normalState, $badState);
     $repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $repository->expects($this->once())->method('findBy')->with(array('user' => $user))->will($this->returnValue($states));
     $this->em->expects($this->once())->method('getRepository')->with('OroWindowsBundle:WindowsState')->will($this->returnValue($repository));
     $this->em->expects($this->once())->method('remove')->with($badState);
     $this->em->expects($this->once())->method('flush');
     $output = 'RENDERED';
     $expectedStates = array('cleanUrl' => $expectedWidgetUrl, 'type' => $widgetType);
     $this->environment->expects($this->once())->method('render')->with("OroWindowsBundle::states.html.twig", array("states" => array(1 => $expectedStates)))->will($this->returnValue($output));
     $this->assertEquals($output, $this->extension->render($this->environment));
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:26,代码来源:WindowsExtensionTest.php


注:本文中的Symfony\Component\Security\Core\SecurityContextInterface::expects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。