diff --git a/LICENSE b/LICENSE index 1e2f2e1..4ecff73 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013-2017, OVH SAS. +Copyright (c) 2013-2023, OVH SAS. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/src/Api.php b/src/Api.php index 644dae4..4a237ae 100644 --- a/src/Api.php +++ b/src/Api.php @@ -1,5 +1,5 @@ getStatusCode() === 204 || $response->getBody()->getSize() === 0) { + return null; + } return json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR); } diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 4c8d2e2..7696466 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -1,5 +1,5 @@ assertSame($test['sig'], $req->getHeaderLine('X-Ovh-Signature')); } } + + public function testEmptyResponseBody() + { + $client = new MockClient( + // GET /auth/time + new Response(200, [], MOCK_TIME), + // POST /domain/zone/nonexisting.ovh/refresh + new Response(204, [], ''), + ); + + $api = new Api(MOCK_APPLICATION_KEY, MOCK_APPLICATION_SECRET, 'ovh-eu', MOCK_CONSUMER_KEY, $client); + $response = $api->post('/domain/zone/nonexisting.ovh/refresh'); + $this->assertSame(null, $response); + + $calls = $client->calls; + $this->assertCount(2, $calls); + + $req = $calls[0]['request']; + $this->assertSame('GET', $req->getMethod()); + $this->assertSame('https://eu.api.ovh.com/1.0/auth/time', $req->getUri()->__toString()); + + $req = $calls[1]['request']; + $this->assertSame('POST', $req->getMethod()); + $this->assertSame('https://eu.api.ovh.com/1.0/domain/zone/nonexisting.ovh/refresh', $req->getUri()->__toString()); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dbcd754..84fd0c3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,5 @@