Skip to content

Commit d0f9345

Browse files
committed
fix php map, add test case for get inventory
1 parent 59ca8bd commit d0f9345

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

modules/swagger-codegen/src/main/resources/php/APIClient.mustache

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,17 +376,16 @@ class ApiClient {
376376
{
377377
if (null === $data) {
378378
$deserialized = null;
379-
} elseif (substr($class, 0, 4) == 'map[') {
379+
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
380380
$inner = substr($class, 4, -1);
381-
$values = array();
381+
$deserialized = array();
382382
if(strrpos($inner, ",") !== false) {
383383
$subClass_array = explode(',', $inner, 2);
384384
$subClass = $subClass_array[1];
385385
foreach ($data as $key => $value) {
386-
$values[] = array($key => self::deserialize($value, $subClass));
386+
$deserialized[$key] = self::deserialize($value, $subClass);
387387
}
388388
}
389-
$deserialized = $values;
390389
} elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) {
391390
$subClass = substr($class, 6, -1);
392391
$values = array();

samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,16 @@ public static function deserialize($data, $class)
381381
{
382382
if (null === $data) {
383383
$deserialized = null;
384-
} elseif (substr($class, 0, 4) == 'map[') {
384+
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
385385
$inner = substr($class, 4, -1);
386-
$values = array();
386+
$deserialized = array();
387387
if(strrpos($inner, ",") !== false) {
388388
$subClass_array = explode(',', $inner, 2);
389389
$subClass = $subClass_array[1];
390390
foreach ($data as $key => $value) {
391-
$values[] = array($key => self::deserialize($value, $subClass));
391+
$deserialized[$key] = self::deserialize($value, $subClass);
392392
}
393393
}
394-
$deserialized = $values;
395394
} elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) {
396395
$subClass = substr($class, 6, -1);
397396
$values = array();

samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function testAddPet()
181181
$this->assertSame($response->name, 'PHP Unit Test');
182182
}
183183

184-
// test
184+
// test upload file
185185
public function testUploadFile()
186186
{
187187
// initialize the API client
@@ -194,6 +194,20 @@ public function testUploadFile()
194194
$this->assertSame($add_response, NULL);
195195
}
196196

197+
// test get inventory
198+
public function testGetInventory()
199+
{
200+
// initialize the API client
201+
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
202+
$store_api = new SwaggerClient\StoreAPI($api_client);
203+
// get inventory
204+
$get_response = $store_api->getInventory();
205+
206+
$this->assertInternalType("int", $get_response['sold']);
207+
$this->assertInternalType("int", $get_response['pending']);
208+
209+
}
210+
197211
}
198212

199213
?>

0 commit comments

Comments
 (0)