<?php require_once __DIR__ . '/SwaggerClient-php/autoload.php'; // show error reporting //ini_set('display_errors', 1); //error_reporting(~0); // 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 Swagger\Client\Configuration::getDefaultConfiguration()->setTempFolderPath('/var/tmp/php/'); $petId = 10005; // ID of pet that needs to be fetched 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(); $pet_api->getApiClient()->getConfig()->setTempFolderPath('/var/tmp/php/'); // test default header //$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903"); // return Pet (model) $response = $pet_api->getPetById($petId); // to test __toString() print $response; // add pet (post json) $new_pet_id = 10005; $new_pet = new Swagger\Client\Model\Pet();
public function testGetInventory() { // initialize the API client $config = new Swagger\Client\Configuration(); $config->setHost('http://petstore.swagger.io/v2'); $api_client = new Swagger\Client\APIClient($config); $store_api = new Swagger\Client\Api\StoreAPI($api_client); // get inventory $get_response = $store_api->getInventory(); $this->assertInternalType("int", $get_response['sold']); $this->assertInternalType("int", $get_response['pending']); }
public function testGetPetByIdWithByteArray() { // initialize the API client $config = new Swagger\Client\Configuration(); $config->setHost('http://petstore.swagger.io/v2'); $api_client = new Swagger\Client\APIClient($config); $pet_api = new Swagger\Client\Api\PetAPI($api_client); // test getPetByIdWithByteArray $pet_id = 10005; $bytes = $pet_api->getPetByIdWithByteArray($pet_id); $json = json_decode(call_user_func_array('pack', array_merge(array('C*'), $bytes)), true); $this->assertInternalType("array", $bytes); $this->assertSame($json['id'], $pet_id); // not testing name as it's tested by addPetUsingByteArray //$this->assertSame($json['name'], 'PHP Unit Test'); $this->assertSame($json['category']['id'], $pet_id); $this->assertSame($json['category']['name'], 'test php category'); $this->assertSame($json['tags'][0]['id'], $pet_id); $this->assertSame($json['tags'][0]['name'], 'test php tag'); }
<?php require_once __DIR__ . '/SwaggerClient-php/autoload.php'; // show error reporting //ini_set('display_errors', 1); //error_reporting(~0); // to debug report print Swagger\Client\Configuration::toDebugReport(); // to change temp folder path Swagger\Client\Configuration::getDefaultConfiguration()->setTempFolderPath('/var/tmp/php/'); // to enable logging Swagger\Client\Configuration::getDefaultConfiguration()->setDebug(true); Swagger\Client\Configuration::getDefaultConfiguration()->setDebugFile('/var/tmp/php_debug.log'); $petId = 10005; // ID of pet that needs to be fetched 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(); $pet_api->getApiClient()->getConfig()->setTempFolderPath('/var/tmp/php/'); // test default header //$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903"); // return Pet (model) $response = $pet_api->getPetById($petId); // to test __toString() print $response; // add pet (post json) $new_pet_id = 10005; $new_pet = new Swagger\Client\Model\Pet();