From d0f9345c5a75d08b0407b2f6da9be8ea385b2eb8 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 5 Jun 2015 13:16:30 +0800 Subject: [PATCH] fix php map, add test case for get inventory --- .../src/main/resources/php/APIClient.mustache | 7 +++---- .../php/SwaggerClient-php/lib/APIClient.php | 7 +++---- .../php/SwaggerClient-php/tests/PetApiTest.php | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/APIClient.mustache b/modules/swagger-codegen/src/main/resources/php/APIClient.mustache index f2106dc6e43..476d3b625c2 100644 --- a/modules/swagger-codegen/src/main/resources/php/APIClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/APIClient.mustache @@ -376,17 +376,16 @@ class ApiClient { { if (null === $data) { $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { + } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] $inner = substr($class, 4, -1); - $values = array(); + $deserialized = array(); if(strrpos($inner, ",") !== false) { $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { - $values[] = array($key => self::deserialize($value, $subClass)); + $deserialized[$key] = self::deserialize($value, $subClass); } } - $deserialized = $values; } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { $subClass = substr($class, 6, -1); $values = array(); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php index 5415ff66972..229709562ef 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php @@ -381,17 +381,16 @@ class ApiClient { { if (null === $data) { $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { + } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] $inner = substr($class, 4, -1); - $values = array(); + $deserialized = array(); if(strrpos($inner, ",") !== false) { $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { - $values[] = array($key => self::deserialize($value, $subClass)); + $deserialized[$key] = self::deserialize($value, $subClass); } } - $deserialized = $values; } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { $subClass = substr($class, 6, -1); $values = array(); diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index d02b8e74558..390cf332b23 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -181,7 +181,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertSame($response->name, 'PHP Unit Test'); } - // test + // test upload file public function testUploadFile() { // initialize the API client @@ -194,6 +194,20 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertSame($add_response, NULL); } + // test get inventory + public function testGetInventory() + { + // initialize the API client + $api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); + $store_api = new SwaggerClient\StoreAPI($api_client); + // get inventory + $get_response = $store_api->getInventory(); + + $this->assertInternalType("int", $get_response['sold']); + $this->assertInternalType("int", $get_response['pending']); + + } + } ?>