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

63 lines
2.2 KiB
PHP
Raw Normal View History

2015-04-06 10:03:15 +00:00
<?php
2015-06-12 22:01:25 +00:00
require_once(__DIR__ . '/SwaggerClient-php/autoload.php');
2015-04-06 10:03:15 +00:00
// show error reporting
//ini_set('display_errors', 1);
//error_reporting(~0);
2015-05-26 15:20:34 +00:00
// to enable logging
//Swagger\Client\Configuration::$debug = true;
//Swagger\Client\Configuration::$debug_file = '/var/tmp/php_debug.log';
// 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/');
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);
$pet_api = new Swagger\Client\Api\PetApi();
2015-06-26 15:55:51 +00:00
$pet_api->getApiClient()->getConfig()->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)
$response = $pet_api->getPetById($petId);
2015-06-17 11:00:29 +00:00
// to test __toString()
print ($response);
// add pet (post json)
$new_pet_id = 10005;
2015-06-12 22:01:25 +00:00
$new_pet = new Swagger\Client\Model\Pet;
2015-06-26 09:06:30 +00:00
$new_pet->setId($new_pet_id);
$new_pet->setName("PHP Unit Test");
// new tag
2015-06-12 22:01:25 +00:00
$tag= new Swagger\Client\Model\Tag;
2015-06-26 09:06:30 +00:00
$tag->setId($new_pet_id); // 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";
2015-06-26 09:06:30 +00:00
$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 upload file (should return exception)
$upload_response = $pet_api->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: ', $e->getResponseHeaders(), "\n";
echo 'HTTP response body: ', $e->getResponseBody(), "\n";
echo 'HTTP status code: ', $e->getCode(), "\n";
2015-04-06 10:03:15 +00:00
}