public function testBodyReadyJson()
 {
     $body = '["foo", {"bar":["baz", null, 1.0, 2]}]';
     $stream = fopen('php://memory', 'r+');
     fwrite($stream, $body);
     rewind($stream);
     $this->response['body'] = $stream;
     $request = ['http_method' => 'PUT', 'headers' => []];
     $ff = $this->futureFunc;
     $handler = $ff($this->response);
     $middleware = Middleware::processResponse($handler, $this->logger);
     /** @var FutureArray $future */
     $future = $middleware($request);
     $result = $future->wait();
     $this->assertTrue(is_array($result));
     $this->assertArrayHasKey('body', $result);
     $this->assertJson($result['body']);
     $this->assertArrayHasKey('json', $result);
     $this->assertNotNull($result['json']);
 }
Пример #2
0
 /**
  * @return Client
  */
 public function build()
 {
     $this->validate();
     if (null === $this->logger) {
         $this->logger = new NullLogger();
     }
     if (null === $this->handler) {
         $this->handler = ClientBuilder::defaultHandler();
     }
     $this->handler = Middleware::signRequest($this->handler, $this->clientKey, $this->clientSecret);
     $this->handler = Middleware::processResponse($this->handler, $this->logger);
     if (null === $this->transport) {
         $this->transport = new Transport($this->handler, new RequestBuilder($this->baseUrl));
     }
     return new Client($this->transport);
 }