本文整理匯總了PHP中Symfony\Component\HttpKernel\HttpKernelInterface::expects方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpKernelInterface::expects方法的具體用法?PHP HttpKernelInterface::expects怎麽用?PHP HttpKernelInterface::expects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpKernel\HttpKernelInterface
的用法示例。
在下文中一共展示了HttpKernelInterface::expects方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testUnbannedIp
/**
* Tests an unbanned IP.
*/
public function testUnbannedIp()
{
$unbanned_ip = '18.0.0.2';
$this->banManager->expects($this->once())->method('isBanned')->with($unbanned_ip)->willReturn(FALSE);
$request = Request::create('/test-path');
$request->server->set('REMOTE_ADDR', $unbanned_ip);
$expected_response = new Response(200);
$this->kernel->expects($this->once())->method('handle')->with($request, HttpKernelInterface::MASTER_REQUEST, TRUE)->willReturn($expected_response);
$response = $this->banMiddleware->handle($request);
$this->assertSame($expected_response, $response);
}
示例2: testHandleWithGetRequest
/**
* Tests onHandleException with a GET request.
*/
public function testHandleWithGetRequest()
{
$request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
$this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
}));
$event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new \Exception('foo'));
$this->exceptionListener->onKernelException($event);
$response = $event->getResponse();
$this->assertEquals('GET name=druplicon&pass=12345 ', $response->getContent() . " " . UrlHelper::buildQuery($request->request->all()));
}
示例3: testOnKernelRequestForward
public function testOnKernelRequestForward()
{
$queryParameters = array( 'some' => 'thing' );
$cookieParameters = array( 'cookie' => 'value' );
$request = Request::create( '/test_sa/foo/bar', 'GET', $queryParameters, $cookieParameters );
$semanticPathinfo = '/foo/something';
$request->attributes->set( 'semanticPathinfo', $semanticPathinfo );
$request->attributes->set( 'needsForward', true );
$request->attributes->set( 'someAttribute', 'someValue' );
$expectedForwardRequest = Request::create( $semanticPathinfo, 'GET', $queryParameters, $cookieParameters );
$expectedForwardRequest->attributes->set( 'semanticPathinfo', $semanticPathinfo );
$expectedForwardRequest->attributes->set( 'someAttribute', 'someValue' );
$response = new Response( 'Success!' );
$this->httpKernel
->expects( $this->once() )
->method( 'handle' )
->with( $this->equalTo( $expectedForwardRequest ) )
->will( $this->returnValue( $response ) );
$event = new GetResponseEvent( $this->httpKernel, $request, HttpKernelInterface::MASTER_REQUEST );
$this->requestEventListener->onKernelRequestForward( $event );
$this->assertSame( $response, $event->getResponse() );
$this->assertTrue( $event->isPropagationStopped() );
}
示例4: testHandleWithGetRequest
/**
* Tests onHandleException with a GET request.
*/
public function testHandleWithGetRequest()
{
$request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
$this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
}));
$event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new NotFoundHttpException('foo'));
$this->customPageSubscriber->onException($event);
$response = $event->getResponse();
$result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
$this->assertEquals('GET name=druplicon&pass=12345&destination=test&_exception_statuscode=404 ', $result);
}
示例5: testHandleWithGetRequest
/**
* Tests onHandleException with a GET request.
*/
public function testHandleWithGetRequest()
{
$request = Request::create('/test', 'GET', array('name' => 'druplicon', 'pass' => '12345'));
$request->attributes->set(AccessAwareRouterInterface::ACCESS_RESULT, AccessResult::forbidden()->addCacheTags(['druplicon']));
$request_context = new RequestContext();
$request_context->fromRequest($request);
$this->accessUnawareRouter->expects($this->any())->method('getContext')->willReturn($request_context);
$this->kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
return new Response($request->getMethod() . ' ' . UrlHelper::buildQuery($request->query->all()));
}));
$event = new GetResponseForExceptionEvent($this->kernel, $request, 'foo', new NotFoundHttpException('foo'));
$this->customPageSubscriber->onException($event);
$response = $event->getResponse();
$result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
$this->assertEquals('GET name=druplicon&pass=12345&destination=test&_exception_statuscode=404 ', $result);
$this->assertEquals(AccessResult::forbidden()->addCacheTags(['druplicon', 'foo', 'bar']), $request->attributes->get(AccessAwareRouterInterface::ACCESS_RESULT));
}