当前位置: 首页>>代码示例>>PHP>>正文


PHP Middleware::history方法代码示例

本文整理汇总了PHP中GuzzleHttp\Middleware::history方法的典型用法代码示例。如果您正苦于以下问题:PHP Middleware::history方法的具体用法?PHP Middleware::history怎么用?PHP Middleware::history使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Middleware的用法示例。


在下文中一共展示了Middleware::history方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSend

 public function testSend()
 {
     $container = [];
     $history = Middleware::history($container);
     $mockResponseData = json_encode(['ok' => true, 'foo' => 'bar']);
     $mock = new MockHandler([new Response(200, [], $mockResponseData)]);
     $stack = HandlerStack::create($mock);
     $stack->push($history);
     $client = new Client(['handler' => $stack]);
     $mockPayload = new MockPayload();
     $foo = 'who:(search+query+OR+other+search+query)';
     $mockPayload->setFoo($foo);
     $apiClient = new ApiClient(self::API_KEY, $client);
     $payloadResponse = $apiClient->send($mockPayload);
     $transaction = array_pop($container);
     // Assert response is of type MockPayloadResponse
     $this->assertInstanceOf('Colada\\Europeana\\Tests\\Test\\Payload\\MockPayloadResponse', $payloadResponse);
     // Assert if the responses match up.
     $transaction['response']->getBody();
     $this->assertEquals($mockResponseData, $transaction['response']->getBody());
     // Assert if the URL is unfuddled.
     $expectedRequestUri = sprintf('http://europeana.eu/api/v2/mock.json?foo=%s&wskey=%s', $foo, self::API_KEY);
     $requestUri = $transaction['request']->getUri();
     $this->assertEquals($expectedRequestUri, $requestUri);
 }
开发者ID:netsensei,项目名称:europeana,代码行数:25,代码来源:ApiClientTest.php

示例2: testSend

 /**
  * @covers ::send
  * @covers ::buildRequest
  * @covers ::getGzippedBody
  * @covers ::getAuthorization
  */
 public function testSend()
 {
     $container = array();
     $history = Middleware::history($container);
     $mockHandler = new MockHandler(array(new Response(200, array(), 'Everything OK')));
     $stack = HandlerStack::create($mockHandler);
     $stack->push($history);
     // $stack->push($mockHandler);
     $http = new GuzzleAdapter(new GuzzleClient(array('handler' => $stack)));
     $client = new Client('aaaaa', 'bbbbb', $http);
     $message = new Message('http://www.example.com/', $client);
     $message->set('foo', 'bar');
     // Call send() and ensure the right response was returned (which we set up above)
     $response = $message->send();
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('Everything OK', $response->getBody());
     // Ensure the request has everything that should be there
     $this->assertCount(1, $container);
     $request = $container[0]['request'];
     $this->assertEquals('POST', $request->getMethod());
     $this->assertEquals('http://www.example.com/', (string) $request->getUri());
     $this->assertEquals('gzip', $request->getHeaderLine('Content-Encoding'));
     $this->assertEquals('application/json', $request->getHeaderLine('Content-Type'));
     $this->assertEquals('2Isi0VhuV8oniANJzAZVBEZ3DSAKmP0hQrVh3jbUNaQ=', $request->getHeaderLine('Authorization'));
     $this->assertEquals('H4sIAAAAAAAAA6tWSsvPV7JSSkosUqoFAO/1K/4NAAAA', base64_encode((string) $request->getBody()));
 }
开发者ID:maartenstaa,项目名称:gameanalytics-php,代码行数:32,代码来源:MessageTest.php

示例3: __construct

 public function __construct($email, $password, SessionStorageInterface $sessionStorage = null, $env = 'prod', $debug = false)
 {
     if (!in_array($env, ['test', 'prod'], true)) {
         throw new InvalidArgumentException("Environment must be one of: prod, test");
     }
     if (null === $sessionStorage) {
         if (php_sapi_name() == "cli") {
             $sessionStorage = new MemorySessionStorage();
         } else {
             $sessionStorage = new NativeSessionStorage();
         }
     }
     $this->sessionStorage = $sessionStorage;
     $this->email = $email;
     $this->password = $password;
     $params = ['base_uri' => $this->{$env . 'Url'}];
     if ($debug) {
         $this->transactionHistory = [];
         $history = Middleware::history($this->transactionHistory);
         $stack = HandlerStack::create();
         $stack->push($history);
         $params['handler'] = $stack;
     }
     $this->client = new Client($params);
 }
开发者ID:CodeNet-pl,项目名称:kk-client,代码行数:25,代码来源:KKClient.php

示例4: testBasicClient

 public function testBasicClient()
 {
     $mock = new MockHandler([new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}")]);
     $container = [];
     $history = Middleware::history($container);
     $stack = HandlerStack::create($mock);
     $stack->push($history);
     $http_client = new Client(['handler' => $stack]);
     $client = new BuuyersClient('u', 'p');
     $client->setClient($http_client);
     $client->companies->getCompany(1);
     foreach ($container as $transaction) {
         $basic = $transaction['request']->getHeaders()['Authorization'][0];
         $this->assertTrue($basic == "Basic dTpw");
         $method = $transaction['request']->getMethod();
         $this->assertEquals($method, 'GET');
         //> GET
         if ($transaction['response']) {
             $statusCode = $transaction['response']->getStatusCode();
             $this->assertEquals(200, $statusCode);
             //> 200, 200
         } elseif ($transaction['error']) {
             echo $transaction['error'];
             //> exception
         }
     }
 }
开发者ID:buuyers,项目名称:buuyers-api-php,代码行数:27,代码来源:BuuyersClientTest.php

示例5: testValidateTicket

 /**
  * Test validation of Cas tickets.
  *
  * @covers ::__construct
  * @covers ::validateTicket
  * @covers ::validateVersion1
  * @covers ::validateVersion2
  * @covers ::verifyProxyChain
  * @covers ::parseAllowedProxyChains
  * @covers ::parseServerProxyChain
  *
  * @dataProvider validateTicketDataProvider
  */
 public function testValidateTicket($version, $ticket, $username, $response, $is_proxy, $can_be_proxied, $proxy_chains, $ssl_verification)
 {
     $mock = new MockHandler([new Response(200, array(), $response)]);
     $handler = HandlerStack::create($mock);
     $container = [];
     $history = Middleware::history($container);
     $handler->push($history);
     $httpClient = new Client(['handler' => $handler]);
     $casHelper = $this->getMockBuilder('\\Drupal\\cas\\Service\\CasHelper')->disableOriginalConstructor()->getMock();
     $casValidator = new CasValidator($httpClient, $casHelper);
     $casHelper->expects($this->any())->method('getCasProtocolVersion')->will($this->returnValue($version));
     $casHelper->expects($this->once())->method('getSslVerificationMethod')->willReturn($ssl_verification);
     $casHelper->expects($this->any())->method('getCertificateAuthorityPem')->will($this->returnValue('foo'));
     $casHelper->expects($this->any())->method('isProxy')->will($this->returnValue($is_proxy));
     $casHelper->expects($this->any())->method('canBeProxied')->will($this->returnValue($can_be_proxied));
     $casHelper->expects($this->any())->method('getProxyChains')->will($this->returnValue($proxy_chains));
     $property_bag = $casValidator->validateTicket($version, $ticket, array());
     // Test that we sent the correct ssl option to the http client.
     foreach ($container as $transaction) {
         switch ($ssl_verification) {
             case CasHelper::CA_CUSTOM:
                 $this->assertEquals('foo', $transaction['options']['verify']);
                 break;
             case CasHelper::CA_NONE:
                 $this->assertEquals(FALSE, $transaction['options']['verify']);
                 break;
             default:
                 $this->assertEquals(TRUE, $transaction['options']['verify']);
         }
     }
     $this->assertEquals($username, $property_bag->getUsername());
 }
开发者ID:pulibrary,项目名称:recap,代码行数:45,代码来源:CasValidatorTest.php

示例6: testSend

 public function testSend()
 {
     $self = $this;
     $mockRequestData = ['foo' => 'bar', 'token' => self::TOKEN];
     $mockResponseData = ['ok' => true, 'foo' => 'bar'];
     $handler = HandlerStack::create(new MockHandler([new Response(200, [], json_encode($mockResponseData))]));
     $historyContainer = [];
     $history = Middleware::history($historyContainer);
     $handler->push($history);
     $apiClient = new ApiClient(self::TOKEN, new Client(['handler' => $handler]));
     $apiClient->addRequestListener(function (RequestEvent $event) use(&$eventsDispatched, $mockRequestData, $self) {
         $eventsDispatched[ApiClient::EVENT_REQUEST] = true;
         $self->assertEquals($mockRequestData, $event->getRawPayload());
     });
     $apiClient->addResponseListener(function (ResponseEvent $event) use(&$eventsDispatched, $mockResponseData, $self) {
         $eventsDispatched[ApiClient::EVENT_RESPONSE] = true;
         $self->assertEquals($mockResponseData, $event->getRawPayloadResponse());
     });
     $mockPayload = new MockPayload();
     $mockPayload->setFoo('bar');
     $apiClient->send($mockPayload);
     $transaction = $historyContainer[0];
     $requestUrl = (string) $transaction['request']->getUri();
     $requestContentType = $transaction['request']->getHeader('content-type')[0];
     parse_str($transaction['request']->getBody(), $requestBody);
     $responseBody = json_decode($transaction['response']->getBody(), true);
     $this->assertEquals(ApiClient::API_BASE_URL . 'mock', $requestUrl);
     $this->assertEquals('application/x-www-form-urlencoded', $requestContentType);
     $this->assertEquals($mockRequestData, $requestBody);
     $this->assertEquals($mockResponseData, $responseBody);
     $this->assertArrayHasKey(ApiClient::EVENT_REQUEST, $eventsDispatched);
     $this->assertArrayHasKey(ApiClient::EVENT_RESPONSE, $eventsDispatched);
 }
开发者ID:billhance,项目名称:slack,代码行数:33,代码来源:ApiClientTest.php

示例7: getHttpClient

 /**
  * Get the client for making calls
  *
  * @return Client
  */
 public function getHttpClient()
 {
     if ($this->client == null) {
         $handler = HandlerStack::create();
         if ($this->mode == 'record') {
             $history = Middleware::history($this->callList);
             $handler->push($history);
         } elseif ($this->mode == 'playback') {
             $recordings = $this->getRecordings();
             $playList = $recordings;
             $mockedResponses = [];
             foreach ($playList as $item) {
                 $mockedResponses[] = new Response($item['statusCode'], $item['headers'], $item['body']);
             }
             $mockHandler = new MockHandler($mockedResponses);
             $handler = HandlerStack::create($mockHandler);
         }
         $this->client = new Client(['handler' => $handler]);
         if (!$this->shutdownRegistered) {
             register_shutdown_function(array($this, 'endRecord'));
             $this->shutdownRegistered = true;
         }
     }
     return $this->client;
 }
开发者ID:eldiddio,项目名称:php-ews,代码行数:30,代码来源:HttpPlayback.php

示例8: testDetailArray

 public function testDetailArray()
 {
     $mock = new MockHandler([new Response(200, ['Content-Type' => 'application/json'], '{
                 "id": "main",
                 "authorizedFor": "Myself",
                 "creator": {
                     "id": "1234",
                     "description": "me@keboola.com"
                 },
                 "created": "2016-01-31 00:13:30",
                 "#data": "KBC::ComponentProjectEncrypted==F2LdyHQB45lJHtf",
                 "oauthVersion": "2.0",
                 "appKey": "1234",
                 "#appSecret": "KBC::ComponentEncrypted==/5fEM59+3+59+5+"
             }')]);
     // Add the history middleware to the handler stack.
     $container = [];
     $history = Middleware::history($container);
     $stack = HandlerStack::create($mock);
     $stack->push($history);
     $cred = new Credentials('some-token', ['handler' => $stack, 'url' => 'https://syrup.keboola.com/oauth-v2/']);
     $cred->enableReturnArrays(true);
     $result = $cred->getDetail('wr-dropbox', 'credentials-id');
     $this->assertInternalType('array', $result);
     $this->assertCount(8, $result);
     $this->assertArrayHasKey('#data', $result);
     $this->assertArrayHasKey('#appSecret', $result);
     /** @var Request $request */
     $request = $container[0]['request'];
     $this->assertEquals("https://syrup.keboola.com/oauth-v2/credentials/wr-dropbox/credentials-id", $request->getUri()->__toString());
     $this->assertEquals("GET", $request->getMethod());
     $this->assertEquals("some-token", $request->getHeader("x-storageapi-token")[0]);
 }
开发者ID:keboola,项目名称:oauth-v2-php-client,代码行数:33,代码来源:CredentialsTest.php

示例9: getMockHttpClientWithHistoryAndResponses

 /**
  * Get Guzzle with mock response and request history stored in container
  *
  * @param array $container
  * @param Response[] $responses
  * @return Client
  */
 public function getMockHttpClientWithHistoryAndResponses(&$container, $responses)
 {
     $mock = new MockHandler($responses);
     $stack = HandlerStack::create($mock);
     $history = Middleware::history($container);
     $stack->push($history);
     return new Client(['handler' => $stack]);
 }
开发者ID:bobbyshaw,项目名称:ibm-watson-visual-recognition-php,代码行数:15,代码来源:Base.php

示例10: getGuzzle

 /**
  * @param null|string $response
  * @return GuzzleClient
  * @see ClientTest::getGuzzle()
  * @link https://github.com/FriendsOfPHP/Goutte/blob/master/Goutte/Tests/ClientTest.php
  */
 protected function getGuzzle($response)
 {
     $handlerStack = HandlerStack::create(new MockHandler([new GuzzleResponse(200, [], $response)]));
     $history = [];
     $handlerStack->push(Middleware::history($history));
     $guzzle = new GuzzleClient(['redirect.disable' => true, 'base_uri' => '', 'handler' => $handlerStack]);
     return $guzzle;
 }
开发者ID:jamband,项目名称:ripple,代码行数:14,代码来源:ClientTrait.php

示例11: buildMockedClient

 public static function buildMockedClient(array &$container, array $responses)
 {
     $history = Middleware::history($container);
     $mock = new MockHandler($responses);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     return new Client(['handler' => $handler]);
 }
开发者ID:softwareontherocks,项目名称:cryptosdks,代码行数:8,代码来源:TestUtils.php

示例12: setUp

 public function setUp()
 {
     $this->context = new Context(['keys' => ['pda' => 'secret'], 'algorithm' => 'hmac-sha256', 'headers' => ['(request-target)', 'date']]);
     $stack = new HandlerStack();
     $stack->setHandler(new MockHandler([new Response(200, ['Content-Length' => 0])]));
     $stack->push(GuzzleHttpSignatures::middlewareFromContext($this->context));
     $stack->push(Middleware::history($this->history));
     $this->client = new Client(['handler' => $stack]);
 }
开发者ID:99designs,项目名称:http-signatures-guzzlehttp,代码行数:9,代码来源:GuzzleHttpSignerTest.php

示例13: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     $mock = new MockHandler([new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CityResponse>    <ResultCount>618</ResultCount>    <Cities>        <City>            <RcAbbreviation>PINEHURST</RcAbbreviation>            <Name>ABERDEEN</Name>        </City>        <City>            <RcAbbreviation>JULIAN</RcAbbreviation>            <Name>ADVANCE</Name>        </City>    </Cities></CityResponse>"), new Response(200, [], "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><RateCenters>    <ResultCount>652</ResultCount>    <RateCenters>        <RateCenter>            <Abbreviation>AGOURA</Abbreviation>            <Name>AGOURA</Name>        </RateCenter>        <RateCenter>            <Abbreviation>ALAMITOS</Abbreviation>            <Name>ALAMITOS</Name>        </RateCenter>    </RateCenters></RateCenters>")]);
     self::$container = [];
     $history = Middleware::history(self::$container);
     $handler = HandlerStack::create($mock);
     $handler->push($history);
     self::$client = new Iris\Client("test", "test", array('url' => 'https://api.test.inetwork.com/v1.0', 'handler' => $handler));
 }
开发者ID:bandwidthcom,项目名称:php-bandwidth-iris,代码行数:9,代码来源:OtherTest.php

示例14: setUp

 protected function setUp()
 {
     $mock = new MockHandler([new Response(200, ["X-Foo" => "Bar"], "It worked!")]);
     $stack = HandlerStack::create($mock);
     $history = Middleware::history($this->container);
     $stack->push($history);
     $client = new Client(["handler" => $stack]);
     $this->object = new GuzzleTransport($client);
 }
开发者ID:metasyntactical,项目名称:http-transport-guzzle,代码行数:9,代码来源:GuzzleTransportTest.php

示例15: initClient

 /**
  * @before
  */
 public function initClient()
 {
     $this->requests = [];
     $stack = HandlerStack::create();
     $stack->push(Middleware::history($this->requests));
     $this->client = new Client(['handler' => $stack]);
     $this->api = new Mailchimp($this->client, getenv('MAILCHIMP_API_KEY'));
     $this->faker = Factory::create();
 }
开发者ID:digital-canvas,项目名称:mailchimp-api,代码行数:12,代码来源:MailchimpTestTrait.php


注:本文中的GuzzleHttp\Middleware::history方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。