本文整理汇总了PHP中Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthorizationCheckerInterface::expects方法的具体用法?PHP AuthorizationCheckerInterface::expects怎么用?PHP AuthorizationCheckerInterface::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
的用法示例。
在下文中一共展示了AuthorizationCheckerInterface::expects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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->pwcMock->expects($this->at(0))->method('isGranted')->with(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->equalTo($block))->will($this->returnValue(true));
$this->pwcMock->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->pwcMock, $this->requestStackMock, 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());
}
示例2: testIsGrantedWithException
public function testIsGrantedWithException()
{
$this->setExpectedException('RuntimeException', 'Something is wrong');
$this->admin->expects($this->any())->method('getCode')->will($this->returnValue('foo.bar'));
$this->authorizationChecker->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');
}
示例3: testOnKernelRequestAccessGranted
public function testOnKernelRequestAccessGranted()
{
$request = new Request();
$request->attributes->set('siteaccess', new SiteAccess());
$event = new GetResponseEvent($this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
$token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
$token->expects($this->any())->method('getUsername')->will($this->returnValue('foo'));
$this->tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($token));
$this->authChecker->expects($this->once())->method('isGranted')->will($this->returnValue(true));
// Nothing should happen or should be returned.
$this->listener->onKernelRequest($event);
}
示例4: testIsGrantedWithVoter
public function testIsGrantedWithVoter()
{
$this->parameterResolver->expects($this->once())->method('resolveVoter')->will($this->returnValue(true));
$this->authorizationChecker->expects($this->once())->method('isGranted')->with($this->identicalTo('lug.' . ($action = 'show')), $this->identicalTo($object = $this->createStdClassMock()))->will($this->returnValue(true));
$this->assertTrue($this->securityChecker->isGranted($action, $object));
}