-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathAsyncTest.php
More file actions
88 lines (72 loc) · 2.39 KB
/
AsyncTest.php
File metadata and controls
88 lines (72 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?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
{
$config = (new Configuration())->setHost('http://localhost/v2');
$this->api = new Api\PetApi(null, $config);
$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();
}
}