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


PHP HandlerStack::resolve方法代碼示例

本文整理匯總了PHP中GuzzleHttp\HandlerStack::resolve方法的典型用法代碼示例。如果您正苦於以下問題:PHP HandlerStack::resolve方法的具體用法?PHP HandlerStack::resolve怎麽用?PHP HandlerStack::resolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GuzzleHttp\HandlerStack的用法示例。


在下文中一共展示了HandlerStack::resolve方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: performTestRequest

 private function performTestRequest($logger, $request, $response)
 {
     $stack = new HandlerStack(new MockHandler([$response]));
     $stack->push(LoggingMiddleware::forLogger($logger));
     $handler = $stack->resolve();
     return $handler($request, [])->wait();
 }
開發者ID:jberkel,項目名稱:tool,代碼行數:7,代碼來源:LoggingMiddlewareTest.php

示例2: testCanRemoveMiddlewareByInstance

 public function testCanRemoveMiddlewareByInstance()
 {
     $meths = $this->getFunctions();
     $builder = new HandlerStack();
     $builder->setHandler($meths[1]);
     $builder->push($meths[2]);
     $builder->push($meths[2]);
     $builder->push($meths[3]);
     $builder->push($meths[4]);
     $builder->push($meths[2]);
     $builder->remove($meths[3]);
     $composed = $builder->resolve();
     $this->assertEquals('Hello - test1131', $composed('test'));
 }
開發者ID:nystudio107,項目名稱:instantanalytics,代碼行數:14,代碼來源:HandlerStackTest.php

示例3: testNullStopwatch

 /**
  * @dataProvider expectProvider
  *
  * @param int $duration The expected duration.
  */
 public function testNullStopwatch($duration)
 {
     // HandlerStack
     $response = new Response(200);
     $stack = new HandlerStack(new MockHandler([$response]));
     // Middleware
     $middleware = new StopwatchMiddleware();
     $stack->push($middleware);
     $handler = $stack->resolve();
     // Request
     $request = new Request('GET', 'http://example.com');
     $promise = $handler($request, []);
     $response = $promise->wait();
     $this->assertNotEquals($response->getHeaderLine('X-Duration'), $duration);
 }
開發者ID:bmancone,項目名稱:guzzle-stopwatch-middleware,代碼行數:20,代碼來源:StopwatchMiddlewareTest.php

示例4: testLogsRequestsAndErrors

 public function testLogsRequestsAndErrors()
 {
     $h = new MockHandler([new Response(404)]);
     $stack = new HandlerStack($h);
     $logger = new Logger();
     $formatter = new MessageFormatter('{code} {error}');
     $stack->push(Middleware::log($logger, $formatter));
     $stack->push(Middleware::httpErrors());
     $comp = $stack->resolve();
     $p = $comp(new Request('PUT', 'http://www.google.com'), ['http_errors' => true]);
     $p->wait(false);
     $this->assertContains('PUT http://www.google.com', $logger->output);
     $this->assertContains('404 Not Found', $logger->output);
 }
開發者ID:nystudio107,項目名稱:instantanalytics,代碼行數:14,代碼來源:MiddlewareTest.php

示例5: testSubscriberDoesNotDoAnythingForNonGigyaAuthRequests

 public function testSubscriberDoesNotDoAnythingForNonGigyaAuthRequests()
 {
     $handler = new MockHandler([function (RequestInterface $request, array $options) {
         $query = $request->getUri()->getQuery();
         $this->assertNotRegExp('/apiKey=/', $query);
         $this->assertNotRegExp('/secret=/', $query);
         $this->assertNotRegExp('/userKey=/', $query);
         return new Response(200);
     }]);
     $stack = new HandlerStack($handler);
     $stack->push(HttpsAuthMiddleware::middleware('key', 'secret', 'user'));
     $comp = $stack->resolve();
     $promise = $comp(new Request('GET', 'http://example.com'), ['auth' => 'oauth']);
     $this->assertInstanceOf(PromiseInterface::class, $promise);
 }
開發者ID:graze,項目名稱:gigya-client,代碼行數:15,代碼來源:HttpsAuthMiddlewareTest.php

示例6: testIgnoresIfExpectIsPresent

 public function testIgnoresIfExpectIsPresent()
 {
     $bd = Psr7\stream_for(fopen(__DIR__ . '/../composer.json', 'r'));
     $h = new MockHandler([function (RequestInterface $request) {
         $this->assertEquals(['Foo'], $request->getHeader('Expect'));
         return new Response(200);
     }]);
     $m = Middleware::prepareBody();
     $stack = new HandlerStack($h);
     $stack->push($m);
     $comp = $stack->resolve();
     $p = $comp(new Request('PUT', 'http://www.google.com', ['Expect' => 'Foo'], $bd), ['expect' => true]);
     $this->assertInstanceOf(PromiseInterface::class, $p);
     $response = $p->wait();
     $this->assertEquals(200, $response->getStatusCode());
 }
開發者ID:nystudio107,項目名稱:instantanalytics,代碼行數:16,代碼來源:PrepareBodyMiddlewareTest.php

示例7: testInvokesOnRedirectForRedirects

 public function testInvokesOnRedirectForRedirects()
 {
     $mock = new MockHandler([new Response(302, ['Location' => 'http://test.com']), new Response(200)]);
     $stack = new HandlerStack($mock);
     $stack->push(Middleware::redirect());
     $handler = $stack->resolve();
     $request = new Request('GET', 'http://example.com?a=b');
     $call = false;
     $promise = $handler($request, ['allow_redirects' => ['max' => 2, 'on_redirect' => function ($request, $response, $uri) use(&$call) {
         $this->assertEquals(302, $response->getStatusCode());
         $this->assertEquals('GET', $request->getMethod());
         $this->assertEquals('http://test.com', (string) $uri);
         $call = true;
     }]]);
     $promise->wait();
     $this->assertTrue($call);
 }
開發者ID:nystudio107,項目名稱:instantanalytics,代碼行數:17,代碼來源:RedirectMiddlewareTest.php

示例8: testErrorWhenNoTokenIsReturnedWillNotIntercept

 public function testErrorWhenNoTokenIsReturnedWillNotIntercept()
 {
     $handler = new MockHandler([function (RequestInterface $request) {
         $this->assertEquals('', $request->getHeaderLine('Authorization'));
         return new Response(401);
     }]);
     $this->grant->shouldReceive('getToken')->atLeast()->once()->andReturn(null);
     $stack = new HandlerStack($handler);
     $stack->push(OAuth2Middleware::middleware($this->grant));
     $comp = $stack->resolve();
     /** @var PromiseInterface $promise */
     $promise = $comp(new Request('GET', 'https://example.com'), ['auth' => 'gigya-oauth2']);
     $this->assertInstanceOf(PromiseInterface::class, $promise);
     /** @var ResponseInterface $response */
     $response = $promise->wait(true);
     $this->assertEquals(401, $response->getStatusCode());
 }
開發者ID:graze,項目名稱:gigya-client,代碼行數:17,代碼來源:OAuth2MiddlewareTest.php


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