fix php map, add test case for get inventory

This commit is contained in:
wing328 2015-06-05 13:16:30 +08:00
parent 59ca8bd986
commit d0f9345c5a
3 changed files with 21 additions and 9 deletions

View File

@ -376,17 +376,16 @@ class ApiClient {
{ {
if (null === $data) { if (null === $data) {
$deserialized = null; $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); $inner = substr($class, 4, -1);
$values = array(); $deserialized = array();
if(strrpos($inner, ",") !== false) { if(strrpos($inner, ",") !== false) {
$subClass_array = explode(',', $inner, 2); $subClass_array = explode(',', $inner, 2);
$subClass = $subClass_array[1]; $subClass = $subClass_array[1];
foreach ($data as $key => $value) { 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) { } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) {
$subClass = substr($class, 6, -1); $subClass = substr($class, 6, -1);
$values = array(); $values = array();

View File

@ -381,17 +381,16 @@ class ApiClient {
{ {
if (null === $data) { if (null === $data) {
$deserialized = null; $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); $inner = substr($class, 4, -1);
$values = array(); $deserialized = array();
if(strrpos($inner, ",") !== false) { if(strrpos($inner, ",") !== false) {
$subClass_array = explode(',', $inner, 2); $subClass_array = explode(',', $inner, 2);
$subClass = $subClass_array[1]; $subClass = $subClass_array[1];
foreach ($data as $key => $value) { 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) { } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) {
$subClass = substr($class, 6, -1); $subClass = substr($class, 6, -1);
$values = array(); $values = array();

View File

@ -181,7 +181,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
$this->assertSame($response->name, 'PHP Unit Test'); $this->assertSame($response->name, 'PHP Unit Test');
} }
// test // test upload file
public function testUploadFile() public function testUploadFile()
{ {
// initialize the API client // initialize the API client
@ -194,6 +194,20 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
$this->assertSame($add_response, NULL); $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']);
}
} }
?> ?>