From f54185c66d05eab2b3f3d7c9bf3910a5d5d39f7b Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 14 Jan 2016 17:27:21 +0800 Subject: [PATCH 1/3] add binary support for php response --- .../codegen/languages/PhpClientCodegen.java | 1 + .../src/main/resources/php/ApiClient.mustache | 2 +- .../resources/php/ObjectSerializer.mustache | 2 + .../SwaggerClientTest.userprefs | 17 +- ...ClientTest.csproj.FilesWrittenAbsolute.txt | 9 + .../php/SwaggerClient-php/lib/Api/PetApi.php | 186 ++++++++++++++++++ .../php/SwaggerClient-php/lib/ApiClient.php | 2 +- .../lib/ObjectSerializer.php | 2 + .../SwaggerClient-php/tests/PetApiTest.php | 22 +++ 9 files changed, 236 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java index 3e3ae868e3f..12e6b3ea8ed 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java @@ -97,6 +97,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("array", "array"); typeMapping.put("list", "array"); typeMapping.put("object", "object"); + typeMapping.put("binary", "ByteArray"); cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC)); cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC)); diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index f4d5c9401a7..defea63b138 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -230,7 +230,7 @@ class ApiClient throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { // return raw body if response is a file - if ($responseType == '\SplFileObject') { + if ($responseType == '\SplFileObject' || $responseType == 'ByteArray') { return array($http_body, $response_info['http_code'], $http_header); } diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index a264c13af30..6cc2206b455 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -241,6 +241,8 @@ class ObjectSerializer $values[] = $this->deserialize($value, $subClass); } $deserialized = $values; + } elseif ($class === 'ByteArray') { // byte array + $deserialized = unpack('C*', (string)$data); } elseif ($class === '\DateTime') { $deserialized = new \DateTime($data); } elseif (in_array($class, array({{&primitives}}))) { diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs index 34b1a516f28..4a3939f7094 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs @@ -1,18 +1,25 @@  - + - - + + + - + + + + + + + @@ -22,4 +29,4 @@ - + \ No newline at end of file diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt index f115c595d6a..8a50eed1027 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt +++ b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt @@ -1,3 +1,12 @@ +/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs +/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png +/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb +/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll +/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll +/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb +/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll +/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll +/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index c853583d0eb..bc1a5729bf5 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -873,4 +873,190 @@ class PetApi } } + /** + * getPetByIdWithByteArray + * + * Fake endpoint to test byte array return by 'Find pet by ID' + * + * @param int $pet_id ID of pet that needs to be fetched (required) + * @return ByteArray + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getPetByIdWithByteArray($pet_id) + { + list($response, $statusCode, $httpHeader) = $this->getPetByIdWithByteArrayWithHttpInfo ($pet_id); + return $response; + } + + + /** + * getPetByIdWithByteArrayWithHttpInfo + * + * Fake endpoint to test byte array return by 'Find pet by ID' + * + * @param int $pet_id ID of pet that needs to be fetched (required) + * @return Array of ByteArray, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getPetByIdWithByteArrayWithHttpInfo($pet_id) + { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetByIdWithByteArray'); + } + + // parse inputs + $resourcePath = "/pet/{petId}?testing_byte_array=true"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + // path params + + if ($pet_id !== null) { + $resourcePath = str_replace( + "{" . "petId" . "}", + $this->apiClient->getSerializer()->toPathValue($pet_id), + $resourcePath + ); + } + // default format to json + $resourcePath = str_replace("{format}", "json", $resourcePath); + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { + $httpBody = $formParams; // for HTTP post (form) + } + + // this endpoint requires API key authentication + $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); + if (strlen($apiKey) !== 0) { + $headerParams['api_key'] = $apiKey; + } + + + // make the API Call + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( + $resourcePath, 'GET', + $queryParams, $httpBody, + $headerParams, 'ByteArray' + ); + + if (!$response) { + return array(null, $statusCode, $httpHeader); + } + + return array($this->apiClient->getSerializer()->deserialize($response, 'ByteArray', $httpHeader), $statusCode, $httpHeader); + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'ByteArray', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + + throw $e; + } + } + + /** + * addPetUsingByteArray + * + * Fake endpoint to test byte array in body parameter for adding a new pet to the store + * + * @param ByteArray $body Pet object in the form of byte array (optional) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function addPetUsingByteArray($body = null) + { + list($response, $statusCode, $httpHeader) = $this->addPetUsingByteArrayWithHttpInfo ($body); + return $response; + } + + + /** + * addPetUsingByteArrayWithHttpInfo + * + * Fake endpoint to test byte array in body parameter for adding a new pet to the store + * + * @param ByteArray $body Pet object in the form of byte array (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function addPetUsingByteArrayWithHttpInfo($body = null) + { + + + // parse inputs + $resourcePath = "/pet?testing_byte_array=true"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/json','application/xml')); + + + + + // default format to json + $resourcePath = str_replace("{format}", "json", $resourcePath); + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { + $httpBody = $formParams; // for HTTP post (form) + } + + // this endpoint requires OAuth (access token) + if (strlen($this->apiClient->getConfig()->getAccessToken()) !== 0) { + $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken(); + } + + // make the API Call + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( + $resourcePath, 'POST', + $queryParams, $httpBody, + $headerParams + ); + + return array(null, $statusCode, $httpHeader); + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + + throw $e; + } + } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index 97c82f0051e..310a0bdc726 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -230,7 +230,7 @@ class ApiClient throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { // return raw body if response is a file - if ($responseType == '\SplFileObject') { + if ($responseType == '\SplFileObject' || $responseType == 'ByteArray') { return array($http_body, $response_info['http_code'], $http_header); } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index e7417fc42f2..1a5a46d4128 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -241,6 +241,8 @@ class ObjectSerializer $values[] = $this->deserialize($value, $subClass); } $deserialized = $values; + } elseif ($class === 'ByteArray') { // byte array + $deserialized = unpack('C*', (string)$data); } elseif ($class === '\DateTime') { $deserialized = new \DateTime($data); } elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) { diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index a7f53d5c5ba..9ac5bd53b15 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -255,6 +255,28 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertInternalType("int", $get_response['pending']); } + // test byte array response + public function testGetPetByIdWithByteArray() + { + // initialize the API client + $config = new Swagger\Client\Configuration(); + $config->setHost('http://petstore.swagger.io/v2'); + $api_client = new Swagger\Client\APIClient($config); + $pet_api = new Swagger\Client\Api\PetAPI($api_client); + // test getPetByIdWithByteArray + $pet_id = 10005; + $bytes = $pet_api->getPetByIdWithByteArray($pet_id); + $json = json_decode(call_user_func_array('pack', array_merge(array('C*'), $bytes )), true); + + $this->assertInternalType("array", $bytes); + + $this->assertSame($json['id'], $pet_id); + $this->assertSame($json['name'], 'PHP Unit Test'); + $this->assertSame($json['category']['id'], $pet_id); + $this->assertSame($json['category']['name'], 'test php category'); + $this->assertSame($json['tags'][0]['id'], $pet_id); + $this->assertSame($json['tags'][0]['name'], 'test php tag'); + } } ?> From c7b9635e9801e3f860c19f2f56d0eb70d91c0cf4 Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 14 Jan 2016 21:57:55 +0800 Subject: [PATCH 2/3] add test cases for byte array (body) --- .../petstore/php/SwaggerClient-php/tests/PetApiTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 9ac5bd53b15..345c42b408c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -206,7 +206,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase } // test addPet and verify by the "id" and "name" of the response - public function testAddPet() + public function testAddPetUsingByteArray() { // initialize the API client $config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2'); @@ -217,7 +217,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $new_pet->setName("PHP Unit Test"); $pet_api = new Swagger\Client\Api\PetAPI($api_client); // add a new pet (model) - $add_response = $pet_api->addPet($new_pet); + $add_response = $pet_api->addPetUsingByteArray(unpack('C*', $new_pet)); // return nothing (void) $this->assertSame($add_response, NULL); // verify added Pet @@ -225,6 +225,8 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertSame($response->getId(), $new_pet_id); $this->assertSame($response->getName(), 'PHP Unit Test'); } + + // test upload file public function testUploadFile() From fee8acef9722b8b790d1c72eac1cfc5290bcec4b Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 15 Jan 2016 00:20:36 +0800 Subject: [PATCH 3/3] fix isBinary, CodegenParameter copy, add isBinary to php api client --- .../io/swagger/codegen/CodegenParameter.java | 1 + .../io/swagger/codegen/DefaultCodegen.java | 10 ++-- .../src/main/resources/php/api.mustache | 2 +- .../php/SwaggerClient-php/lib/Api/PetApi.php | 2 +- .../SwaggerClient-php/tests/PetApiTest.php | 51 ++++++++++++++++--- 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java index ab934075a53..9bf2858161d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenParameter.java @@ -110,6 +110,7 @@ public class CodegenParameter { output.allowableValues = new HashMap(this.allowableValues); } output.vendorExtensions = this.vendorExtensions; + output.isBinary = this.isBinary; return output; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 1056e854f8a..abc4d045315 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1329,6 +1329,7 @@ public class DefaultCodegen { cookieParams.add(p.copy()); } else if (param instanceof BodyParameter) { p.isBodyParam = new Boolean(true); + p.isBinary = p.dataType.toLowerCase().startsWith("byte"); bodyParam = p; bodyParams.add(p.copy()); } else if (param instanceof FormParameter) { @@ -1422,7 +1423,7 @@ public class DefaultCodegen { } } r.dataType = cm.datatype; - r.isBinary = cm.datatype.equals("byte[]"); + r.isBinary = cm.datatype.toLowerCase().startsWith("byte"); if (cm.isContainer != null) { r.simpleType = false; r.containerType = cm.containerType; @@ -1567,12 +1568,7 @@ public class DefaultCodegen { CodegenProperty cp = fromProperty("property", prop); if (cp != null) { p.dataType = cp.datatype; - if (p.dataType.equals("byte[]")) { - p.isBinary = true; - } - else { - p.isBinary = false; - } + p.isBinary = cp.datatype.toLowerCase().startsWith("byte"); } } } else if (model instanceof ArrayModel) { diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index c0c497ff418..6d1a3d570f7 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -188,7 +188,7 @@ use \{{invokerPackage}}\ObjectSerializer; {{#bodyParams}}// body params $_tempBody = null; if (isset(${{paramName}})) { - $_tempBody = ${{paramName}}; + {{^isBinary}}$_tempBody = ${{paramName}};{{/isBinary}}{{#isBinary}}$_tempBody = call_user_func_array('pack', array_merge(array('C*'), ${{paramName}}));{{/isBinary}} }{{/bodyParams}} // for model (json/xml) diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index bc1a5729bf5..66e8f34df09 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -1026,7 +1026,7 @@ class PetApi // body params $_tempBody = null; if (isset($body)) { - $_tempBody = $body; + $_tempBody = call_user_func_array('pack', array_merge(array('C*'), $body)); } // for model (json/xml) diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 345c42b408c..dfc45971209 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -204,26 +204,62 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertSame($response->getName(), 'update pet with form'); $this->assertSame($response->getStatus(), 'sold'); } - + // test addPet and verify by the "id" and "name" of the response - public function testAddPetUsingByteArray() + public function testAddPet() { // initialize the API client $config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2'); $api_client = new Swagger\Client\ApiClient($config); - $new_pet_id = 10001; + $new_pet_id = 10005; $new_pet = new Swagger\Client\Model\Pet; $new_pet->setId($new_pet_id); - $new_pet->setName("PHP Unit Test"); + $new_pet->setName("PHP Unit Test 2"); $pet_api = new Swagger\Client\Api\PetAPI($api_client); // add a new pet (model) - $add_response = $pet_api->addPetUsingByteArray(unpack('C*', $new_pet)); + $add_response = $pet_api->addPet($new_pet); // return nothing (void) $this->assertSame($add_response, NULL); // verify added Pet $response = $pet_api->getPetById($new_pet_id); $this->assertSame($response->getId(), $new_pet_id); - $this->assertSame($response->getName(), 'PHP Unit Test'); + $this->assertSame($response->getName(), 'PHP Unit Test 2'); + } + + // test addPetUsingByteArray and verify by the "id" and "name" of the response + public function testAddPetUsingByteArray() + { + // initialize the API client + $config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new Swagger\Client\ApiClient($config); + + $new_pet_id = 10005; + $new_pet = new Swagger\Client\Model\Pet; + $new_pet->setId($new_pet_id); + $new_pet->setName("PHP Unit Test 3"); + // new tag + $tag= new Swagger\Client\Model\Tag; + $tag->setId($new_pet_id); // use the same id as pet + $tag->setName("test php tag"); + // new category + $category = new Swagger\Client\Model\Category; + $category->setId($new_pet_id); // use the same id as pet + $category->setName("test php category"); + + $new_pet->setTags(array($tag)); + $new_pet->setCategory($category); + + $pet_api = new Swagger\Client\Api\PetAPI($api_client); + // add a new pet (model) + $object_serializer = new Swagger\Client\ObjectSerializer(); + $pet_json_string = json_encode($object_serializer->sanitizeForSerialization($new_pet)); + $add_response = $pet_api->addPetUsingByteArray(unpack('C*', $pet_json_string)); + // return nothing (void) + $this->assertSame($add_response, NULL); + // verify added Pet + $response = $pet_api->getPetById($new_pet_id); + $this->assertSame($response->getId(), $new_pet_id); + $this->assertSame($response->getName(), 'PHP Unit Test 3'); } @@ -273,7 +309,8 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertInternalType("array", $bytes); $this->assertSame($json['id'], $pet_id); - $this->assertSame($json['name'], 'PHP Unit Test'); + // not testing name as it's tested by addPetUsingByteArray + //$this->assertSame($json['name'], 'PHP Unit Test'); $this->assertSame($json['category']['id'], $pet_id); $this->assertSame($json['category']['name'], 'test php category'); $this->assertSame($json['tags'][0]['id'], $pet_id);