[PHP] check if json_decode was able to decode response (#16879)

* [PHP] check if json_decode was able to decode response

* use try/catch to check if json_decode failed
This commit is contained in:
Artur Neumann
2023-10-31 13:37:33 +05:45
committed by GitHub
parent 08d518319e
commit 6cd73eba2b
11 changed files with 692 additions and 134 deletions

View File

@@ -2,10 +2,12 @@
namespace OpenAPI\Client;
use GuzzleHttp\Psr7\Response;
use OpenAPI\Client\Api\FakeApi;
use OpenAPI\Client\Api\PetApi;
use OpenAPI\Client\Model\Pet;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
require_once __DIR__ . '/FakeHttpClient.php';
@@ -17,6 +19,7 @@ class AuthTest extends TestCase
$authConfig->setApiKey('api_key', '123qwe');
$fakeHttpClient = new FakeHttpClient();
$fakeHttpClient->setResponse(new Response(200, [], json_encode([])));
$api = new PetApi($fakeHttpClient, $authConfig);
$api->getPetById(123);