append() public method

Adds one or more variadic requests, exceptions, callables, or promises to the queue.
public append ( )
示例#1
0
 public function testGetLastRequest()
 {
     $request = new HttpClients\Message\Request('');
     $this->mockHandler->append(new Response('200'));
     $this->client->send($request);
     $this->assertSame($request, $this->client->getLastRequest());
 }
 protected function setUp()
 {
     $this->responsePromise = new Promise();
     $this->mockHandler = new MockHandler([]);
     $this->mockHandler->append($this->responsePromise);
     $this->guzzleClient = new Client(['handler' => $this->mockHandler, 'base_uri' => 'http://localhost:8080/']);
     $this->httpMessageProducer = new HttpMessageProducer($this->guzzleClient, new NoOpMessageConverter());
 }
示例#3
0
 /**
  * @param Response|RequestException|string $response
  * @param string $language
  */
 protected function mockResponse($response, $language = 'en')
 {
     $this->api();
     if (is_string($response)) {
         $this->mock->append(new Response(200, ['Content-Type' => 'application/json; charset=utf-8', 'Content-Language' => $language], Psr7\stream_for($response)));
     } elseif ($response instanceof RequestException) {
         $this->mock->append($response);
     } else {
         $this->mock->append($response);
     }
 }
 public function testRewind()
 {
     $users = $this->client->getRepository(User::class)->findAll();
     $this->assertInstanceOf(UserSet::class, $users);
     $this->guzzleMock->append(new Response(200, ['Content-Type' => 'application/json'], file_get_contents(__DIR__ . '/../Resources/http/admin/users@per_page=100&page=1.json')));
     $originalUser = $users->current();
     $users->next();
     $this->assertNotSame($originalUser, $users->current());
     $users->rewind();
     $this->assertSame($originalUser, $users->current());
 }
示例#5
0
 public function testGetTournamentPrizePool()
 {
     $file = file_get_contents('./tests/Responses/getTournamentPrizePool.json');
     $this->mockHandler->append(new Response('200', [], $file));
     $response = $this->client->getTournamentPrizePool();
     $this->assertArraySubset(json_decode($file, true), $response->getJson());
 }
 /**
  * @covers ::load
  * @covers ::loadMultiple
  * @covers ::request
  * @covers ::parseResponse
  */
 public function testLoadWithAvailableExchangeRate()
 {
     $expectedExchangeRate = sprintf('%s.%s', mt_rand(), mt_rand());
     $httpResponse = $this->getMock(ResponseInterface::class);
     $httpResponse->expects($this->atLeastOnce())->method('getBody')->willReturn(sprintf('"EURUSP=X",%s', $expectedExchangeRate));
     $this->httpClientHandler->append($httpResponse);
     $exchangeRate = $this->sut->load('EUR', 'UAH');
     $this->assertInstanceOf('\\Commercie\\CurrencyExchange\\ExchangeRateInterface', $exchangeRate);
     $this->assertSame($expectedExchangeRate, $exchangeRate->getRate());
 }
示例#7
0
 /**
  * Test get
  */
 public function testGet()
 {
     $responseData = ['success' => true];
     $this->mockHandler->append(new Response(200, [], json_encode($responseData)));
     // Make the call
     $endpoint = '/v4/blah';
     $params = ['some-param' => 'some-value'];
     $actualResponse = $this->api->get($endpoint, $params);
     $this->checkResponse('GET', $endpoint, $params, $responseData, $actualResponse, true);
 }
示例#8
0
 /**
  * Instantiate a client
  */
 public function doSetup($requestNumber)
 {
     $handler = new MockHandler([]);
     for ($i = 0; $i < $requestNumber; $i++) {
         $handler->append(new Response(200));
     }
     $guzzle = new GuzzleClient(["handler" => $handler]);
     $this->requestFactory = $this->getMock('Silktide\\SemRushApi\\Model\\Factory\\RequestFactory');
     $this->request = $this->getMockBuilder('Silktide\\SemRushApi\\Model\\Request')->disableOriginalConstructor()->getMock();
     $this->requestFactory->expects($this->exactly($requestNumber))->method('create')->willReturn($this->request);
     $this->resultFactory = $this->getMockBuilder('Silktide\\SemRushApi\\Model\\Factory\\ResultFactory')->disableOriginalConstructor()->getMock();
     $result = $this->getMockBuilder('Silktide\\SemRushApi\\Model\\Result')->disableOriginalConstructor()->getMock();
     $this->resultFactory->expects($this->exactly(1))->method('create')->willReturn($result);
     $this->responseParser = $this->getMock('Silktide\\SemRushApi\\Helper\\ResponseParser');
     $urlBuilder = $this->getMock('Silktide\\SemRushApi\\Helper\\UrlBuilder');
     $this->instance = new Client($this->key, $this->requestFactory, $this->resultFactory, $this->responseParser, $urlBuilder, $guzzle);
 }
示例#9
0
 public function createAccountInfoHandler()
 {
     $handler = new MockHandler();
     for ($i = 0; $i < 1000; $i++) {
         $handler->append(function () {
             $uid = 'diofu90ifgdf';
             $timestamp = time();
             $signatureValidator = new Signature();
             $signature = $signatureValidator->calculateSignature($timestamp . '_' . $uid, 'secret');
             return new Response(200, [], sprintf('{
                 "UID": "%s",
                 "UIDSignature": "%s",
                 "signatureTimestamp": "%d",
                 "statusCode": 200,
                 "errorCode": 0,
                 "statusReason": "OK",
                 "callId": "123456",
                 "time": "2015-03-22T11:42:25.943Z"
             }', $uid, $signature, $timestamp));
         });
     }
     $this->gigya = new Gigya('key', 'secret', null, null, ['guzzle' => ['handler' => new HandlerStack($handler)]]);
 }
示例#10
0
 /**
  * @param string $token
  * @param Scope $scope
  * @param MockHandler $mockHandler
  */
 public function iAmReadyToRespondToATokenRequest($token, Scope $scope, MockHandler $mockHandler)
 {
     $mockHandler->append($this->rawTokenResponse($token, $scope));
 }
示例#11
0
 /**
  * @param $httpcode
  * @param null $headers
  * @param null $body
  */
 protected function addMockResponse($httpcode, $headers = null, $body = null)
 {
     $this->guzzleMockHandler->append(new Response($httpcode, $headers, $body));
 }
示例#12
0
 public function addRuntimeException(\GuzzleHttp\Handler\MockHandler $mock)
 {
     $mock->append(new \RuntimeException("Runtime error", 999));
 }
 /**
  * Setup the response with Guzzle mock plugin
  *
  * @param string $responseFile
  */
 protected function setupResponse($responseFile)
 {
     $this->guzzleHandler->append(new Response(200, [], ResponseExampleHelper::getResponseExample($responseFile)));
 }
 /**
  * @param string                       $method
  * @param string                       $url
  * @param array                        $headers
  * @param mixed                        $body
  * @param \Exception|ResponseInterface $responseOrException
  */
 protected function mockClientRequest($method, $url, array $headers, $body = null, $responseOrException)
 {
     // TODO it would be nice if we could assert the request arguments as well
     $this->handler->append($responseOrException);
 }