Esempio n. 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";
}
{
    global $prof_timing, $prof_names;
    $size = count($prof_timing);
    for ($i = 0; $i < $size - 1; $i++) {
        echo sprintf("%s => %f\n", $prof_names[$i], $prof_timing[$i + 1] - $prof_timing[$i]);
    }
    echo "{$prof_names[$size - 1]}\n";
}
$counter = 5;
// run 5 times by default
$new_pet_id = 50001;
// ID of pet that needs to be fetched
for ($x = 0; $x <= $counter; $x++) {
    try {
        prof_flag("{$x}: NEW PETAPI");
        $pet_api = new Swagger\Client\Api\PetApi();
        // ~~~ ADD PET ~~~
        prof_flag("{$x}: ADD PET");
        // add pet (post json)
        $new_pet = new Swagger\Client\Model\Pet();
        $new_pet->setId($new_pet_id);
        $new_pet->setName("profiler");
        $new_pet->setStatus("available");
        $new_pet->setPhotoUrls(array("http://profiler.com"));
        // new tag
        $tag = new Swagger\Client\Model\Tag();
        $tag->setId($new_pet_id);
        // use the same id as pet
        $tag->setName("profile tag 1");
        // new category
        $category = new Swagger\Client\Model\Category();
Esempio n. 3
0
 public function testUploadFile()
 {
     // initialize the API client
     $config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2');
     $api_client = new Swagger\Client\ApiClient($config);
     $pet_api = new Swagger\Client\Api\PetApi($api_client);
     // upload file
     $pet_id = 10001;
     $response = $pet_api->uploadFile($pet_id, "test meta", "./composer.json");
     // return ApiResponse
     $this->assertInstanceOf('Swagger\\Client\\Model\\ApiResponse', $response);
 }
 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->petPetIdtestingByteArraytrueGet($pet_id);
     $json = json_decode($bytes, true);
     $this->assertInternalType("string", $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');
 }