本文整理汇总了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();
}
示例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'));
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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());
}