Exemple #1
0
    $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
    //$tag->name = "test php tag";
    // new category
    $category = new Swagger\Client\Model\Category();
    $category->setId(10005);
    // use the same id as pet
    //$category->name = "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 upload file (should return exception)
    $upload_response = $pet_api->uploadFile($petId, "test meta", NULL);
} catch (Swagger\Client\ApiException $e) {
    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";
}
Exemple #2
0
 public function testAddPet()
 {
     // initialize the API client
     $config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2');
     $api_client = new Swagger\Client\ApiClient($config);
     $new_pet_id = 10005;
     $new_pet = new Swagger\Client\Model\Pet();
     $new_pet->setId($new_pet_id);
     $new_pet->setName("PHP Unit Test 2");
     $pet_api = new Swagger\Client\Api\PetApi($api_client);
     // add a new pet (model)
     $add_response = $pet_api->addPet($new_pet);
     // return nothing (void)
     $this->assertSame($add_response, NULL);
     // verify added Pet
     $response = $pet_api->getPetById($new_pet_id);
     $this->assertSame($response->getId(), $new_pet_id);
     $this->assertSame($response->getName(), 'PHP Unit Test 2');
 }