forked from loafle/openapi-generator-original
* Set PHP 7.2 as minimum version * Update PHPUnit to 8 || 9 * Set Bionic environment in Travis config * PHPUnit 8 requires void return in static methods * PHPUnit 8 requires void return in static methods * Fix curl exception message test When I run "curl http://wrong_host.zxc" output is: curl: (6) Could not resolve host: wrong_host.zxc Maybe this message is different across versions. Tested curl version: curl 7.54.0 (x86_64-apple-darwin18.0) libcurl/7.54.0 LibreSSL/2.6.5 zlib/1.2.11 nghttp2/1.24.1 * Update assertions of deprecated assertInternalType * Migrate to expectException method of PHPUnit 8 * Fix PHPCS Fixer errors * Replace deprecated 'assertRegExp' assertion * Exclude PHPUnit and php-cs-fixer cache * Refresh samples * Set root Travis CI environment to PHP 7.2.5 * Change to 7.3 as 7.2.27 is highest preinstalled * Fix testWrongHost test
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace OpenAPI\Client;
|
|
|
|
use OpenAPI\Client\Api\PetApi;
|
|
use OpenAPI\Client\Model\Pet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AsyncTest extends TestCase
|
|
{
|
|
/** @var PetApi */
|
|
private $api;
|
|
|
|
/** @var int */
|
|
private $petId;
|
|
|
|
public function setUp(): void
|
|
{
|
|
$this->api = new Api\PetApi();
|
|
|
|
$this->petId = 10005;
|
|
$pet = new Model\Pet;
|
|
$pet->setId($this->petId);
|
|
$pet->setName("PHP Unit Test");
|
|
$pet->setPhotoUrls(array("http://test_php_unit_test.com"));
|
|
// new tag
|
|
$tag= new Model\Tag;
|
|
$tag->setId($this->petId); // use the same id as pet
|
|
$tag->setName("test php tag");
|
|
// new category
|
|
$category = new Model\Category;
|
|
$category->setId($this->petId); // use the same id as pet
|
|
$category->setName("test php category");
|
|
|
|
$pet->setTags(array($tag));
|
|
$pet->setCategory($category);
|
|
|
|
$pet_api = new Api\PetApi();
|
|
// add a new pet (model)
|
|
$add_response = $pet_api->addPet($pet);
|
|
}
|
|
|
|
public function testAsyncRequest()
|
|
{
|
|
$promise = $this->api->getPetByIdAsync(10005);
|
|
|
|
$promise2 = $this->api->getPetByIdAsync(10005);
|
|
|
|
$pet = $promise->wait();
|
|
$pet2 = $promise2->wait();
|
|
$this->assertInstanceOf(Pet::class, $pet);
|
|
$this->assertInstanceOf(Pet::class, $pet2);
|
|
}
|
|
|
|
public function testAsyncRequestWithHttpInfo()
|
|
{
|
|
$promise = $this->api->getPetByIdAsyncWithHttpInfo($this->petId);
|
|
|
|
list($pet, $status, $headers) = $promise->wait();
|
|
$this->assertEquals(200, $status);
|
|
$this->assertIsArray($headers);
|
|
$this->assertInstanceOf(Pet::class, $pet);
|
|
}
|
|
|
|
public function testAsyncThrowingException()
|
|
{
|
|
$this->expectException(\OpenAPI\Client\ApiException::class);
|
|
$promise = $this->api->getPetByIdAsync(0);
|
|
$promise->wait();
|
|
}
|
|
|
|
/**
|
|
* @doesNotPerformAssertions
|
|
*/
|
|
public function testAsyncApiExceptionWithoutWaitIsNotThrown()
|
|
{
|
|
$promise = $this->api->getPetByIdAsync(0);
|
|
sleep(1);
|
|
}
|
|
|
|
public function testAsyncHttpInfoThrowingException()
|
|
{
|
|
$this->expectException(\OpenAPI\Client\ApiException::class);
|
|
$promise = $this->api->getPetByIdAsyncWithHttpInfo(0);
|
|
$promise->wait();
|
|
}
|
|
}
|