mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-13 00:21:18 +00:00
Rename default packages for php client (#315)
* Rename default packages for php client * Generate php client (OAS3) * Rename namespace for tests * Delete unnecessary 'use' * Rename method/variable * Update php client (OAS3) * Generate php client (OAS2) * Rename namespace for tests * Delete unused files * Fix tests
This commit is contained in:
committed by
William Cheng
parent
e2f8976fa7
commit
376d9af9c0
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace OpenAPITools\Client;
|
||||
|
||||
use OpenAPITools\Client\Api\PetApi;
|
||||
use OpenAPITools\Client\Model\Pet;
|
||||
|
||||
class AsyncTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var PetApi */
|
||||
private $api;
|
||||
|
||||
/** @var int */
|
||||
private $petId;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$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->assertInternalType('array', $headers);
|
||||
$this->assertInstanceOf(Pet::class, $pet);
|
||||
}
|
||||
|
||||
public function testAsyncThrowingException()
|
||||
{
|
||||
$this->setExpectedException(ApiException::class);
|
||||
|
||||
$promise = $this->api->getPetByIdAsync(0);
|
||||
$promise->wait();
|
||||
}
|
||||
|
||||
public function testAsyncApiExceptionWithoutWaitIsNotThrown()
|
||||
{
|
||||
$promise = $this->api->getPetByIdAsync(0);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
public function testAsyncHttpInfoThrowingException()
|
||||
{
|
||||
$this->setExpectedException(ApiException::class);
|
||||
|
||||
$promise = $this->api->getPetByIdAsyncWithHttpInfo(0);
|
||||
$promise->wait();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user