Passed
Push — master ( 06646a...1e9aa0 )
by Darío
04:01 queued 01:55
created

AbstractClientTest::itExecutesARequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 9
rs 10
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