add test case for default header

This commit is contained in:
wing328 2015-05-31 11:17:59 +08:00
parent 83d069d053
commit 8d708c2442
3 changed files with 9 additions and 8 deletions

View File

@ -182,7 +182,7 @@ class APIClient {
$this->updateParamsForAuth($headerParams, $queryParams, $authSettings);
# construct the http header
if ($headerParams != null) {
if ($headerParams !== null) {
# add default header
$headerParams = array_merge((array)self::$default_header, $headerParams);

View File

@ -187,13 +187,10 @@ class APIClient {
$this->updateParamsForAuth($headerParams, $queryParams, $authSettings);
# construct the http header
if ($headerParams != null) {
# add default header
$headerParams = array_merge((array)self::$default_header, $headerParams);
$headerParams = array_merge((array)self::$default_header, (array)$headerParams);
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
}
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
}
// form data
@ -390,7 +387,7 @@ class APIClient {
$deserialized = $values;
} elseif ($class == 'DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool'))) {
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
settype($data, $class);
$deserialized = $data;
} else {

View File

@ -2,6 +2,8 @@
//require_once('vendor/autoload.php');
require_once('SwaggerClient-php/SwaggerClient.php');
$c = array_merge((array)$a, (array)$b);
// initialize the API client
//$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
//$api_client->addDefaultHeader("test1", "value1");
@ -11,6 +13,8 @@ try {
// get pet by id
//$pet_api = new SwaggerClient\PetAPI($api_client);
$pet_api = new SwaggerClient\PetAPI();
// test default header
$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
// return Pet (model)
$response = $pet_api->getPetById($petId);
var_dump($response);