/** * Test storing config options and modifying them. * * @return void */ public function testConstructConfig() { $config = ['scheme' => 'http', 'host' => 'example.org']; $http = new Client($config); $result = $http->config(); foreach ($config as $key => $val) { $this->assertEquals($val, $result[$key]); } $result = $http->config(['auth' => ['username' => 'mark', 'password' => 'secret']]); $this->assertSame($result, $http); $result = $http->config(); $expected = ['scheme' => 'http', 'host' => 'example.org', 'auth' => ['username' => 'mark', 'password' => 'secret']]; foreach ($expected as $key => $val) { $this->assertEquals($val, $result[$key]); } }
/** * {@inheritdoc} */ public function sendRequest(RequestInterface $request) { $cakeRequest = new Request(); $cakeRequest->method($request->getMethod()); $cakeRequest->url((string) $request->getUri()); $cakeRequest->version($request->getProtocolVersion()); $cakeRequest->body($request->getBody()->getContents()); foreach ($request->getHeaders() as $header => $values) { $cakeRequest->header($header, $request->getHeaderLine($header)); } if (null === $cakeRequest->header('Content-Type')) { $cakeRequest->header('Content-Type', 'application/x-www-form-urlencoded'); } try { $cakeResponse = $this->client->send($cakeRequest, $this->client->config()); } catch (Exception $exception) { throw new NetworkException('Failed to send request', $request, $exception); } return $this->responseFactory->createResponse($cakeResponse->statusCode(), null, $cakeResponse->headers(), $cakeResponse->body(), $cakeResponse->version()); }