diff --git a/src/SeatsioException.php b/src/SeatsioException.php index 488a007..f831966 100644 --- a/src/SeatsioException.php +++ b/src/SeatsioException.php @@ -2,6 +2,7 @@ namespace Seatsio; +use GuzzleHttp\Utils; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use RuntimeException; @@ -52,10 +53,10 @@ private static function extractInfo($response) { $contentType = $response->getHeaderLine("content-type"); if (strpos($contentType, 'application/json') !== false) { - $json = \GuzzleHttp\json_decode($response->getBody()); + $json = Utils::jsonDecode($response->getBody()); $mapper = SeatsioJsonMapper::create(); $errors = $mapper->mapArray($json->errors, array(), 'Seatsio\ApiError'); - return ["messages" => $json->messages, "errors" => $errors, "requestId" => $json->requestId]; + return ["messages" => $json->messages, "errors" => $errors, "requestId" => $json->requestId ?? null]; } return ["messages" => [], "errors" => [], "requestId" => null]; } diff --git a/tests/SeatsioExceptionTest.php b/tests/SeatsioExceptionTest.php new file mode 100644 index 0000000..cb3645e --- /dev/null +++ b/tests/SeatsioExceptionTest.php @@ -0,0 +1,175 @@ +requestId); + } +} + + +class DummyRequest implements RequestInterface +{ + + public function __construct() + { + } + + public function getProtocolVersion() + { + } + + public function withProtocolVersion($version) + { + } + + public function getHeaders() + { + } + + public function hasHeader($name) + { + } + + public function getHeader($name) + { + } + + public function getHeaderLine($name) + { + } + + public function withHeader($name, $value) + { + } + + public function withAddedHeader($name, $value) + { + } + + public function withoutHeader($name) + { + } + + public function getBody() + { + } + + public function withBody(StreamInterface $body) + { + } + + public function getRequestTarget() + { + } + + public function withRequestTarget($requestTarget) + { + } + + public function getMethod() + { + } + + public function withMethod($method) + { + } + + public function getUri() + { + } + + public function withUri(UriInterface $uri, $preserveHost = false) + { + } +} + +class DummyResponse implements ResponseInterface +{ + + + private $contentType; + private $body; + + public function __construct(string $contentType, string $body) + { + $this->contentType = $contentType; + $this->body = $body; + } + + public function getProtocolVersion() + { + } + + public function withProtocolVersion($version) + { + } + + public function getHeaders() + { + } + + public function hasHeader($name) + { + } + + public function getHeader($name) + { + } + + public function getHeaderLine($name) + { + if ($name === "content-type") { + return $this->contentType; + } + return null; + } + + public function withHeader($name, $value) + { + } + + public function withAddedHeader($name, $value) + { + } + + public function withoutHeader($name) + { + } + + public function getBody() + { + return $this->body; + } + + public function withBody(StreamInterface $body) + { + } + + public function getStatusCode() + { + } + + public function withStatus($code, $reasonPhrase = '') + { + } + + public function getReasonPhrase() + { + } +}