openapi-generator/samples/client/petstore/php/test.php

63 lines
2.3 KiB
PHP
Raw Normal View History

2015-04-06 10:03:15 +00:00
<?php
Php client using guzzle6 & psr7 instead of curl (#5190) * reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
2017-04-03 07:47:57 +00:00
require_once(__DIR__ . '/SwaggerClient-php/vendor/autoload.php');
2015-04-06 10:03:15 +00:00
// show error reporting
//ini_set('display_errors', 1);
//error_reporting(~0);
// to debug report
print Swagger\Client\Configuration::toDebugReport();
// to change temp folder path
2015-06-26 15:55:51 +00:00
Swagger\Client\Configuration::getDefaultConfiguration()->setTempFolderPath('/var/tmp/php/');
2016-01-20 13:42:51 +00:00
// to enable logging
Swagger\Client\Configuration::getDefaultConfiguration()->setDebug(true);
Swagger\Client\Configuration::getDefaultConfiguration()->setDebugFile('/var/tmp/php_debug.log');
2015-05-26 15:20:34 +00:00
$petId = 10005; // ID of pet that needs to be fetched
2015-04-06 10:03:15 +00:00
try {
// get pet by id
//$api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2');
//$api_client->getConfig()->addDefaultHeader("test1", "value1");
//$pet_api = new Swagger\Client\PetAPI($api_client);
Php client using guzzle6 & psr7 instead of curl (#5190) * reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
2017-04-03 07:47:57 +00:00
$config = new \Swagger\Client\Configuration();
$petApi = new Swagger\Client\Api\PetApi(null, $config);
$config->setTempFolderPath('/var/tmp/php/');
2015-05-31 03:17:59 +00:00
// test default header
2015-06-26 09:06:30 +00:00
//$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
2015-04-06 10:03:15 +00:00
// return Pet (model)
Php client using guzzle6 & psr7 instead of curl (#5190) * reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
2017-04-03 07:47:57 +00:00
$response = $petApi->getPetById($petId);
2015-06-17 11:00:29 +00:00
// to test __toString()
print ($response);
// add pet (post json)
Php client using guzzle6 & psr7 instead of curl (#5190) * reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
2017-04-03 07:47:57 +00:00
$newPetId = 10005;
$newPet = new Swagger\Client\Model\Pet;
$newPet->setId($newPetId);
$newPet->setName("PHP Unit Test");
// new tag
Php client using guzzle6 & psr7 instead of curl (#5190) * reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
2017-04-03 07:47:57 +00:00
$tag = new Swagger\Client\Model\Tag;
$tag->setId($newPetId); // use the same id as pet
//$tag->name = "test php tag";
// new category
2015-06-12 22:01:25 +00:00
$category = new Swagger\Client\Model\Category;
2015-06-26 09:06:30 +00:00
$category->setId(10005); // use the same id as pet
//$category->name = "test php category";
Php client using guzzle6 & psr7 instead of curl (#5190) * reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
2017-04-03 07:47:57 +00:00
$newPet->setTags(array($tag));
$newPet->setCategory($category);
Php client using guzzle6 & psr7 instead of curl (#5190) * reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
2017-04-03 07:47:57 +00:00
$petApi = new Swagger\Client\Api\PetApi(null, $config);
// add a new pet (model)
Php client using guzzle6 & psr7 instead of curl (#5190) * reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
2017-04-03 07:47:57 +00:00
$add_response = $petApi->addPet($newPet);
// test upload file (should return exception)
Php client using guzzle6 & psr7 instead of curl (#5190) * reimplemented basic requests with httpplug * added returning headers * added query params support * removed constant reference to model class * some extra @throws; form params * form and query params encoding * file upload / form multipart * added missing response headers in WithHttpInfo calls * removed Store test From PetApiTest class * removed configuration overriding test as its now task of client adapters * updated store tests with new client initialization code * updated composer.json template * not using json_decode if response is string * renamed some variables to camelCase * removed ApiClient and Configuration classes * added HeaderSelector template * added ObjectSerializer injection * regenerated all samples * added AuthConfig and readded support for custom api keys * readded support for oauth tokens * readded basic auth; moved auth tests to separate test class * readded header params * readded support for collections in paths * readded config option; readded exception handling * file downloading; readded some Configuration properties removed earlier * readded default headers * made responses and return types work same way as earlier * made all methods static in ObjectSerializer * updated test.php, replaced autoload.php with composer's autoloader * updated api doc template * removed classes used for testing; regenerated Fake_classname_tags123Api * replaced httplug with guzzle6 * updated required php version to 5.5 * clean up * readded missing userAgent feature; removed default headers from Configuration * updated test.php * downgraded phpunit back to 4.8 to work with php5.5; fixed client initialization in some tests
2017-04-03 07:47:57 +00:00
$upload_response = $petApi->uploadFile($petId, "test meta", NULL);
} catch (Swagger\Client\ApiException $e) {
2015-04-06 10:03:15 +00:00
echo 'Caught exception: ', $e->getMessage(), "\n";
echo 'HTTP response headers: ', print_r($e->getResponseHeaders(), true), "\n";
echo 'HTTP response body: ', print_r($e->getResponseBody(), true), "\n";
echo 'HTTP status code: ', $e->getCode(), "\n";
2015-04-06 10:03:15 +00:00
}