Keep PHP binary responses as strings for easier manipulation.

This commit is contained in:
Elijah Miller 2016-01-27 12:12:32 -05:00
parent d2bb505147
commit 6698c532e6
5 changed files with 7 additions and 7 deletions

View File

@ -242,7 +242,7 @@ class ObjectSerializer
}
$deserialized = $values;
} elseif ($class === 'ByteArray') { // byte array
$deserialized = unpack('C*', (string)$data);
$deserialized = (string)$data;
} elseif ($class === '\DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array({{&primitives}}))) {

View File

@ -188,7 +188,7 @@ use \{{invokerPackage}}\ObjectSerializer;
{{#bodyParams}}// body params
$_tempBody = null;
if (isset(${{paramName}})) {
{{^isBinary}}$_tempBody = ${{paramName}};{{/isBinary}}{{#isBinary}}$_tempBody = call_user_func_array('pack', array_merge(array('C*'), ${{paramName}}));{{/isBinary}}
$_tempBody = ${{paramName}};
}{{/bodyParams}}
// for model (json/xml)

View File

@ -1036,7 +1036,7 @@ class PetApi
// body params
$_tempBody = null;
if (isset($body)) {
$_tempBody = call_user_func_array('pack', array_merge(array('C*'), $body));
$_tempBody = $body;
}
// for model (json/xml)

View File

@ -242,7 +242,7 @@ class ObjectSerializer
}
$deserialized = $values;
} elseif ($class === 'ByteArray') { // byte array
$deserialized = unpack('C*', (string)$data);
$deserialized = (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'))) {

View File

@ -279,7 +279,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
// 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));
$add_response = $pet_api->addPetUsingByteArray($pet_json_string);
// return nothing (void)
$this->assertSame($add_response, NULL);
// verify added Pet
@ -330,9 +330,9 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
// test getPetByIdWithByteArray
$pet_id = 10005;
$bytes = $pet_api->petPetIdtestingByteArraytrueGet($pet_id);
$json = json_decode(call_user_func_array('pack', array_merge(array('C*'), $bytes )), true);
$json = json_decode($bytes, true);
$this->assertInternalType("array", $bytes);
$this->assertInternalType("string", $bytes);
$this->assertSame($json['id'], $pet_id);
// not testing name as it's tested by addPetUsingByteArray