Skip to content

Commit 23bd142

Browse files
committed
Working on unit tests
1 parent b1623f7 commit 23bd142

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

samples/client/petstore/php/OpenAPIClient-php/tests/ResponseTypesTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use GuzzleHttp\Psr7\Response;
66
use OpenAPI\Client\Api\PetApi;
7+
use OpenAPI\Client\Api\FakeApi;
8+
use OpenAPI\Client\Model\ErrorResponse;
79
use OpenAPI\Client\Model\Pet;
810
use PHPUnit\Framework\TestCase;
911

@@ -114,4 +116,26 @@ public function testNotJSONResponse($statusCode, $responseBody)
114116
$this->fakeHttpClient->setResponse(new Response($statusCode, [], $responseBody));
115117
$this->api->getPetById(123);
116118
}
119+
120+
public function testRangeResponse()
121+
{
122+
$responseCode = mt_rand(400, 499);
123+
$this->fakeHttpClient->setResponse(new Response($responseCode, [], json_encode([])));
124+
$api = new FakeApi($this->fakeHttpClient);
125+
126+
$pet = new Model\Pet([]);
127+
$pet->setId(1234);
128+
129+
$result = $api->fakeWith4xxRangeResponseEndpoint($pet);
130+
131+
$this->assertInstanceOf(Pet::class, $result);
132+
133+
134+
$this->expectExceptionCode(404);
135+
$this->expectException(\OpenAPI\Client\ApiException::class);
136+
$statusCode = 404;
137+
138+
$this->fakeHttpClient->setResponse(new Response($statusCode, [], '{}'));
139+
$this->api->getPetById(123);
140+
}
117141
}

0 commit comments

Comments
 (0)