public function testBuild() { $request = new Request('GET', '/'); $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\BadRequestException', ExceptionFactory::build(RequestException::create($request, new Response('400')))); $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\UnauthorizedException', ExceptionFactory::build(RequestException::create($request, new Response('401')))); $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\ForbiddenException', ExceptionFactory::build(RequestException::create($request, new Response('403')))); $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\NotFoundException', ExceptionFactory::build(RequestException::create($request, new Response('404')))); $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\MethodNotAllowedException', ExceptionFactory::build(RequestException::create($request, new Response('405')))); $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\Client\\NotAcceptableException', ExceptionFactory::build(RequestException::create($request, new Response('406')))); $this->assertInstanceOf('\\keika299\\ConohaAPI\\Common\\Exceptions\\Network\\RequestException', ExceptionFactory::build(RequestException::create($request, new Response('499')))); }
/** * Exec API request. * * This function have to run after set all params. * If $_ENV['IS_TEST'] has value, this function return mock. * * @return Response * @throws \keika299\ConohaAPI\Common\Exceptions\IConohaAPIException */ public function exec() { if (0 < count($this->headers)) { $this->options['headers'] = $this->headers; } $client = $this->getClient(); try { $response = $client->request($this->method, $this->uri . $this->query, $this->options); return new Response($response); } catch (\Exception $e) { throw ExceptionFactory::build($e); } }
/** * Exec API request. * * This function have to run after set all params. * If $_ENV['IS_TEST'] has value, this function return mock. * * @return \keika299\ConohaAPI\Common\Network\Response * @throws \keika299\ConohaAPI\Common\Exceptions\IConohaAPIException */ public function exec() { $options = array(); if ($this->body != null) { $options['body'] = $this->body; } if ($this->json != null) { $options['json'] = $this->json; } if (0 < count($this->headers)) { $options['headers'] = $this->headers; } $client = !isset($_ENV['IS_TEST']) ? new Client(['base_uri' => $this->baseURI]) : $this->createMockClient(); try { $response = $client->request($this->method, $this->uri, $options); return new \keika299\ConohaAPI\Common\Network\Response($response); } catch (\Exception $e) { throw ExceptionFactory::build($e); } }