當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HttpKernelInterface::expects方法代碼示例

本文整理匯總了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);
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:14,代碼來源:BanMiddlewareTest.php

示例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()));
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:14,代碼來源:ExceptionListenerTest.php

示例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() );
    }
開發者ID:ezsystemstraining,項目名稱:ez54training,代碼行數:26,代碼來源:RequestEventListenerTest.php

示例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);
 }
開發者ID:sojo,項目名稱:d8_friendsofsilence,代碼行數:15,代碼來源:CustomPageExceptionHtmlSubscriberTest.php

示例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));
 }
開發者ID:eigentor,項目名稱:tommiblog,代碼行數:20,代碼來源:CustomPageExceptionHtmlSubscriberTest.php


注:本文中的Symfony\Component\HttpKernel\HttpKernelInterface::expects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。