diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 3a4f8dfc8be3..b43c83dd8844 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -175,7 +175,7 @@ class ApiClient { throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { // return raw body if response is a file - if ($responseType == 'SplFileObject') { + if ($responseType == '\SplFileObject') { return array($http_body, $http_header); } @@ -187,7 +187,7 @@ class ApiClient { throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", $response_info['http_code'], $http_header, $http_body); } - return $data; + return array($data, $http_header); } /* diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 26999668b9e9..8e433e6185bf 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -133,7 +133,7 @@ class ObjectSerializer { } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { settype($data, $class); $deserialized = $data; - } elseif ($class === 'SplFileObject') { + } elseif ($class === '\SplFileObject') { # determine temp folder path if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) { $tmpFolderPath = sys_get_temp_dir(); @@ -149,7 +149,7 @@ class ObjectSerializer { } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); } else { $instance = new $class(); diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 367ba037d598..dcbc8b4b3a61 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -134,7 +134,7 @@ class {{classname}} { {{/authMethods}} // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}}); } catch (ApiException $e) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index afbe1991690e..64ef731c4b0f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -110,7 +110,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -171,7 +171,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -231,7 +231,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]'); } catch (ApiException $e) { @@ -302,7 +302,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]'); } catch (ApiException $e) { @@ -387,7 +387,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet'); } catch (ApiException $e) { @@ -473,7 +473,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -544,7 +544,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -619,7 +619,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index 5c9d38a8b5e2..c047182133d5 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -109,7 +109,7 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, 'map[string,int]'); } catch (ApiException $e) { @@ -178,7 +178,7 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order'); } catch (ApiException $e) { @@ -253,7 +253,7 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order'); } catch (ApiException $e) { @@ -328,7 +328,7 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index a95d93bb55e4..d9f2a08ccb8f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -107,7 +107,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -165,7 +165,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -223,7 +223,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -284,7 +284,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, 'string'); } catch (ApiException $e) { @@ -348,7 +348,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -412,7 +412,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\User'); } catch (ApiException $e) { @@ -492,7 +492,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -556,7 +556,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index 92d8c2aa1193..b47e104ec1e1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -175,7 +175,7 @@ class ApiClient { throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { // return raw body if response is a file - if ($responseType == 'SplFileObject') { + if ($responseType == '\SplFileObject') { return array($http_body, $http_header); } @@ -187,7 +187,7 @@ class ApiClient { throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", $response_info['http_code'], $http_header, $http_body); } - return $data; + return array($data, $http_header); } /* diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index d002b3368520..59b7601d1407 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -133,7 +133,7 @@ class ObjectSerializer { } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { settype($data, $class); $deserialized = $data; - } elseif ($class === 'SplFileObject') { + } elseif ($class === '\SplFileObject') { # determine temp folder path if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) { $tmpFolderPath = sys_get_temp_dir(); @@ -149,7 +149,7 @@ class ObjectSerializer { } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); } else { $instance = new $class(); diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 3ac287722915..76c88d20c4e9 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -10,9 +10,11 @@ class PetApiTest extends \PHPUnit_Framework_TestCase // for error reporting (need to run with php5.3 to get no warning) //ini_set('display_errors', 1); //error_reporting(~0); - ini_set('display_startup_errors',1); - ini_set('display_errors',1); - error_reporting(-1); + // when running with php5.5, comment out below to skip the warning about + // using @ to handle file upload + //ini_set('display_startup_errors',1); + //ini_set('display_errors',1); + //error_reporting(-1); // enable debugging //Swagger\Client\Configuration::$debug = true; diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/StoreApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/StoreApiTest.php index 05bd873c993d..fcba8adf20ad 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/StoreApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/StoreApiTest.php @@ -10,6 +10,27 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase // for error reporting (need to run with php5.3 to get no warning) //ini_set('display_errors', 1); //error_reporting(~0); + // new pet + $new_pet_id = 10005; + $new_pet = new Swagger\Client\Model\Pet; + $new_pet->setId($new_pet_id); + $new_pet->setName("PHP Unit Test"); + $new_pet->setStatus("available"); + // new tag + $tag= new Swagger\Client\Model\Tag; + $tag->setId($new_pet_id); // use the same id as pet + $tag->setName("test php tag"); + // new category + $category = new Swagger\Client\Model\Category; + $category->setId($new_pet_id); // use the same id as pet + $category->setName("test php category"); + + $new_pet->setTags(array($tag)); + $new_pet->setCategory($category); + + $pet_api = new Swagger\Client\Api\PetAPI(); + // add a new pet (model) + $add_response = $pet_api->addPet($new_pet); } // test get inventory @@ -22,8 +43,7 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase // get inventory $get_response = $store_api->getInventory(); - $this->assertInternalType("int", $get_response['sold']); - $this->assertInternalType("int", $get_response['pending']); + $this->assertInternalType("int", $get_response['available']); }