本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseEvent::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseEvent::expects方法的具体用法?PHP GetResponseEvent::expects怎么用?PHP GetResponseEvent::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseEvent
的用法示例。
在下文中一共展示了GetResponseEvent::expects方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRequestCompile
public function testRequestCompile()
{
$this->tracker->expects($this->once())->method('isOutdated')->willReturn(true);
$this->compiler->expects($this->once())->method('compile');
$this->dumper->expects($this->once())->method('dump');
$this->event->expects($this->once())->method('isMasterRequest')->willReturn(true);
(new RequestListener($this->tracker, $this->compiler, $this->dumper))->onRequest($this->event);
}
示例2: handleForbidden
/**
* @test
*/
public function handleForbidden()
{
$listener = new WsseListener($this->securityContext, $this->authenticationManager);
$this->request->headers->add(array('X-WSSE' => 'temp'));
$response = new Response();
$response->setStatusCode(403);
//unauthorized
$this->responseEvent->expects($this->once())->method('setResponse')->with($response);
$listener->handle($this->responseEvent);
}
示例3: setUp
/**
* Set up the whole
*/
public function setUp()
{
$this->requestAttributes = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\ParameterBag')->disableOriginalConstructor()->setMethods(array('get'))->getMock();
$request = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
$request->attributes = $this->requestAttributes;
$this->responseEvent = $this->getMockBuilder('\\Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent')->disableOriginalConstructor()->setMethods(array('getRequestType', 'getRequest'))->getMock();
$this->responseEvent->expects($this->any())->method('getRequest')->will($this->returnValue($request));
$this->responseEvent->expects($this->any())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
$this->provider = new BreadcrumbProvider(self::MODEL_CLASS, self::COLLECTION_CLASS);
}
示例4: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
$this->event = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent')->disableOriginalConstructor()->getMock();
$this->request = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
$this->parameterBag = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\ParameterBag')->disableOriginalConstructor()->getMock();
$this->route = $this->getMockBuilder('Symfony\\Component\\Routing\\Route')->disableOriginalConstructor()->getMock();
$this->request->attributes = $this->parameterBag;
$this->event->expects($this->any())->method('getRequest')->will($this->returnValue($this->request));
$this->accessManager = $this->getMockBuilder('Drupal\\Core\\Access\\AccessManager')->disableOriginalConstructor()->getMock();
$this->currentUser = $this->getMockBuilder('Drupal\\Core\\Session\\AccountInterface')->disableOriginalConstructor()->getMock();
}
示例5: getRequest
/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getRequest()
{
$request = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
$this->event->expects($this->once())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
$this->event->expects($this->once())->method('getRequest')->will($this->returnValue($request));
return $request;
}
示例6: getRequest
/**
* @param string $header
* @param string $ip
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getRequest($header, $ip)
{
$this->event->expects($this->once())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
/* @var $request \PHPUnit_Framework_MockObject_MockObject|Request */
$request = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
$request->server = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ServerBag');
$request->server->expects($this->atLeastOnce())->method('get')->will($this->returnCallback(function ($value) use($header, $ip) {
return $value == $header ? $ip : null;
}));
$this->event->expects($this->once())->method('getRequest')->will($this->returnValue($request));
return $request;
}
示例7: handleReturnResponse
/**
* @test
*/
public function handleReturnResponse()
{
$token = new WsseToken();
$token->setUser('admin');
$token->setAttribute('digest', 'admin');
$token->setAttribute('nonce', 'admin');
$token->setAttribute('created', '2010-12-12 20:00:00');
$this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->will($this->returnValue($this->response));
$this->responseEvent->expects($this->once())->method('setResponse')->with($this->response);
$this->request->headers->add(array('X-WSSE' => 'UsernameToken Username="admin", PasswordDigest="admin", Nonce="admin", Created="2010-12-12 20:00:00"'));
$this->wsseListener->handle($this->responseEvent);
}
示例8: it_grants_access_when_authenticated
/**
* @test
*/
public function it_grants_access_when_authenticated()
{
$this->userSessionService->setMinimalUserInfo($this->minimalUserInfo);
$user = new User();
$user->id = $this->minimalUserInfo->getId();
$authToken = new UiTIDToken($user->getRoles());
$authToken->setUser($user);
$this->authenticationManager->expects($this->once())->method('authenticate')->with($this->minimalToken)->willReturn($authToken);
$this->tokenStorage->expects($this->once())->method('setToken')->with($authToken);
// Make sure no Response is set, so the request can be handled by the
// actual controllers.
$this->event->expects($this->never())->method('setResponse');
$this->listener->handle($this->event);
}
示例9: it_returns_an_unauthorized_response_if_jwt_authentication_fails
/**
* @test
*/
public function it_returns_an_unauthorized_response_if_jwt_authentication_fails()
{
$tokenString = 'headers.payload.signature';
$jwt = new Jwt(['alg' => 'none'], [], null, ['headers', 'payload']);
$token = new JwtUserToken($jwt);
$request = new Request([], [], [], [], [], ['HTTP_AUTHORIZATION' => 'Bearer ' . $tokenString], '');
$this->getResponseEvent->expects($this->any())->method('getRequest')->willReturn($request);
$this->jwtDecoderService->expects($this->once())->method('parse')->with(new StringLiteral($tokenString))->willReturn($jwt);
$authenticationException = new AuthenticationException('Authentication failed', 666);
$this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->willThrowException($authenticationException);
$this->getResponseEvent->expects($this->once())->method('setResponse')->willReturnCallback(function (Response $response) {
$this->assertEquals('Authentication failed', $response->getContent());
$this->assertEquals(401, $response->getStatusCode());
});
$this->listener->handle($this->getResponseEvent);
}
示例10: testHandleGatewayWithCheckOnceSuccess
/**
* Test processing gateway with CHECK_ONCE to make sure SESSION gets set.
*
* @covers ::handle
* @covers ::handleGateway
*/
public function testHandleGatewayWithCheckOnceSuccess()
{
$config_factory = $this->getConfigFactoryStub(array('cas.settings' => array('forced_login.enabled' => TRUE, 'forced_login.paths' => array('<front>'), 'gateway.check_frequency' => CasHelper::CHECK_ONCE, 'gateway.paths' => array('<front>'))));
$cas_subscriber = $this->getMockBuilder('\\Drupal\\cas\\Subscriber\\CasSubscriber')->setConstructorArgs(array($this->requestStack, $this->routeMatcher, $config_factory, $this->currentUser, $this->conditionManager, $this->casHelper))->setMethods(NULL)->getMock();
$this->event->expects($this->any())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
$request_object = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Request');
$attributes = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ParameterBag');
$request_object->attributes = $attributes;
$server = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ServerBag');
$request_object->server = $server;
$condition = $this->getMockBuilder('\\Drupal\\Core\\Condition\\ConditionPluginBase')->disableOriginalConstructor()->getMock();
$this->conditionManager->expects($this->any())->method('createInstance')->with('request_path')->will($this->returnValue($condition));
$condition->expects($this->any())->method('setConfiguration')->with(array('<front>'));
$this->conditionManager->expects($this->any())->method('execute')->with($condition)->will($this->onConsecutiveCalls(FALSE, TRUE));
$request_object->expects($this->once())->method('isMethod')->with('GET')->will($this->returnValue(TRUE));
$this->requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue($request_object));
$this->casHelper->expects($this->once())->method('getServerLoginUrl')->will($this->returnValue('https://example.com'));
$this->event->expects($this->once())->method('setResponse');
$cas_subscriber->handle($this->event);
$this->assertArrayHasKey('cas_gateway_checked', $_SESSION);
}
示例11: testOnKernelRequestWithoutMasterRequest
public function testOnKernelRequestWithoutMasterRequest()
{
$this->getResponseEventMock->expects($this->once())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::SUB_REQUEST));
$this->getResponseEventMock->getRequest()->server->expects($this->never())->method('set');
$this->fakeRequestListener->onKernelRequest($this->getResponseEventMock);
}
示例12: testRequestMasterRequest
public function testRequestMasterRequest()
{
$this->guard->expects($this->once())->method('rebuild');
$this->event->expects($this->once())->method('isMasterRequest')->willReturn(true);
(new RequestListener($this->guard))->onRequest($this->event);
}