|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EasyHttp\LayerContracts\Tests\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use EasyHttp\LayerContracts\Tests\Unit\Example\SomeClient; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class AbstractClientTest extends TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @test |
|
12
|
|
|
*/ |
|
13
|
|
|
public function itExecutesARequest() |
|
14
|
|
|
{ |
|
15
|
|
|
$client = new SomeClient(); |
|
16
|
|
|
|
|
17
|
|
|
$response = $client->call('GET', 'http://example.com/api'); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertSame(200, $response->getStatusCode()); |
|
20
|
|
|
$this->assertSame(['key' => 'value'], $response->toJson()); |
|
21
|
|
|
$this->assertSame(['Server' => 'Apache/2.4.38 (Debian)'], $response->getHeaders()); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @test |
|
26
|
|
|
*/ |
|
27
|
|
|
public function itPreparesARequestForExecution() |
|
28
|
|
|
{ |
|
29
|
|
|
$client = new SomeClient(); |
|
30
|
|
|
$client->prepareRequest('GET', 'http://example.com/api'); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertSame('GET', $client->getRequest()->getMethod()); |
|
33
|
|
|
$this->assertSame('http://example.com/api', $client->getRequest()->getUri()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @test |
|
38
|
|
|
*/ |
|
39
|
|
|
public function itExecutesAPreparedRequest() |
|
40
|
|
|
{ |
|
41
|
|
|
$client = new SomeClient(); |
|
42
|
|
|
$client->prepareRequest('GET', 'http://example.com/api'); |
|
43
|
|
|
|
|
44
|
|
|
$response = $client->execute(); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertSame(200, $response->getStatusCode()); |
|
47
|
|
|
$this->assertSame(['key' => 'value'], $response->toJson()); |
|
48
|
|
|
$this->assertSame(['Server' => 'Apache/2.4.38 (Debian)'], $response->getHeaders()); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|