-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClientTest.php
More file actions
47 lines (35 loc) · 1.37 KB
/
ClientTest.php
File metadata and controls
47 lines (35 loc) · 1.37 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
<?php
declare(strict_types=1);
namespace Tests;
use OpenApi\Client;
use Tests\Transports\FakeTransport;
use PHPUnit\Framework\TestCase;
final class ClientTest extends TestCase
{
public function test_it_uses_injected_transport_for_requests(): void
{
$transport = new FakeTransport();
$client = new Client('test-token', $transport);
$response = $client->request(
'POST',
'https://example.com/api/users',
['name' => 'John'],
['page' => 1]
);
$this->assertSame('fake-response', $response);
$this->assertSame('POST', $transport->lastMethod);
$this->assertSame('https://example.com/api/users', $transport->lastUrl);
$this->assertSame(['name' => 'John'], $transport->lastPayload);
$this->assertSame(['page' => 1], $transport->lastParams);
$this->assertSame(1, $transport->callCount);
}
public function test_it_calls_transport_once_per_request(): void
{
$transport = new FakeTransport();
$client = new Client('test-token', $transport);
$client->request('GET', 'https://example.com/one');
$client->request('GET', 'https://example.com/two');
$this->assertSame(2, $transport->callCount);
$this->assertSame('https://example.com/two', $transport->lastUrl);
}
}