Esempio n. 1
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();
    $new_pet->setId($new_pet_id);
    $new_pet->setName("PHP Unit Test");
    // new tag
    $tag = new Swagger\Client\Model\Tag();
    $tag->setId($new_pet_id);
    // use the same id as pet
Esempio n. 2
0
 public function testGetPetByIdWithHttpInfo()
 {
     // initialize the API client without host
     $pet_id = 10005;
     // ID of pet that needs to be fetched
     $pet_api = new Swagger\Client\Api\PetApi();
     $pet_api->getApiClient()->getConfig()->setApiKey('api_key', '111222333444555');
     // return Pet (model)
     list($response, $status_code, $response_headers) = $pet_api->getPetByIdWithHttpInfo($pet_id);
     $this->assertSame($response->getId(), $pet_id);
     $this->assertSame($response->getName(), 'PHP Unit Test');
     $this->assertSame($response->getCategory()->getId(), $pet_id);
     $this->assertSame($response->getCategory()->getName(), 'test php category');
     $this->assertSame($response->getTags()[0]->getId(), $pet_id);
     $this->assertSame($response->getTags()[0]->getName(), 'test php tag');
     $this->assertSame($status_code, 200);
     $this->assertSame($response_headers['Content-Type'], 'application/json');
 }