William Cheng 6434c86afd
[php-nextgen] add php-nextgen client generator (#16480)
* php-nextgen first commit

* [php] Set minimal PHP version to ^8.0 (#14500)

* Set minimal PHP version to ^8.0

* Fix php-nextgen config

* Change stability to BETA

* Add phplint package (#15054)

* [php-nextgen] Rename folders to follow PDS skeleton (#15102)

* Change lib -> src, test -> tests folder

This will make build compliant to PHP-PDS skeleton.
Ref: https://github.com/php-pds/skeleton

* Refresh samples

* Exclude composer.lock from codebase (#15105)

Since client generator is library and not a project it makes sense
to exclude composer.lock from codebase by default.

Ref: http://getcomposer.org/doc/02-libraries.md#lock-file

* Add @generated tag to DocBlocks (#15106)

This tag in draft status right now(PSR-19), but I think we can leverage
from it already.

Ref: https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md#55-generated

* update samples, doc

* update samples

---------

Co-authored-by: Yuriy Belenko <yura-bely@mail.ru>
2023-09-03 16:16:58 +08:00

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();
}
}