mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
Merge pull request #1930 from wing328/php_fix_deserialization
[PHP] add test cases for findPetsByTags
This commit is contained in:
commit
5d156916d7
@ -26,6 +26,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
||||
$new_pet = new Swagger\Client\Model\Pet;
|
||||
$new_pet->setId($new_pet_id);
|
||||
$new_pet->setName("PHP Unit Test");
|
||||
$new_pet->setPhotoUrls(array("http://test_php_unit_test.com"));
|
||||
// new tag
|
||||
$tag= new Swagger\Client\Model\Tag;
|
||||
$tag->setId($new_pet_id); // use the same id as pet
|
||||
@ -99,6 +100,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
||||
$response = $pet_api->getPetById($pet_id);
|
||||
$this->assertSame($response->getId(), $pet_id);
|
||||
$this->assertSame($response->getName(), 'PHP Unit Test');
|
||||
$this->assertSame($response->getPhotoUrls()[0], 'http://test_php_unit_test.com');
|
||||
$this->assertSame($response->getCategory()->getId(), $pet_id);
|
||||
$this->assertSame($response->getCategory()->getName(), 'test php category');
|
||||
$this->assertSame($response->getTags()[0]->getId(), $pet_id);
|
||||
@ -144,6 +146,26 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(count($response), 0); // confirm no object returned
|
||||
}
|
||||
|
||||
// test getPetsByTags and verify by the "id" of the response
|
||||
public function testFindPetsByTags()
|
||||
{
|
||||
// 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);
|
||||
// return Pet (model)
|
||||
$response = $pet_api->findPetsByTags("test php tag");
|
||||
$this->assertGreaterThan(0, count($response)); // at least one object returned
|
||||
$this->assertSame(get_class($response[0]), "Swagger\\Client\\Model\\Pet"); // verify the object is Pet
|
||||
// loop through result to ensure status is "available"
|
||||
foreach ($response as $_pet) {
|
||||
$this->assertSame($_pet['tags'][0]['name'], "test php tag");
|
||||
}
|
||||
// test invalid status
|
||||
$response = $pet_api->findPetsByTags("unknown_and_incorrect_tag");
|
||||
$this->assertSame(count($response), 0); // confirm no object returned
|
||||
}
|
||||
|
||||
// test updatePet (model/json)and verify by the "id" of the response
|
||||
public function testUpdatePet()
|
||||
{
|
||||
|
@ -5,15 +5,14 @@ require_once(__DIR__ . '/SwaggerClient-php/autoload.php');
|
||||
//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/');
|
||||
// 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user