当前位置: 首页>>代码示例>>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;未经允许,请勿转载。