Passed
Push — master ( 4a3e7e...eed543 )
by Guillermo A.
01:38
created

testRequestWithHeadersWithoutBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GuillermoandraeTest\Highrise\Http;
4
5
use Guillermoandrae\Highrise\Http\GuzzleAdapter;
6
use Guillermoandrae\Highrise\Http\RequestException;
7
use GuillermoandraeTest\Highrise\TestCase;
8
use GuzzleHttp\Client;
9
10
class GuzzleAdapterTest extends TestCase
11
{
12
    public function testRequestWithBody()
13
    {
14
        $body = '<test><name>test</name></test>';
15
        $client = $this->getMockClient(201);
16
        $adapter = $this->getAdapter($client);
17
        $adapter->request('GET', '/test.xml', ['body' => $body]);
18
        $this->assertSame($body, (string) $adapter->getLastRequest()->getBody());
19
    }
20
21
    public function testRequestWithoutBody()
22
    {
23
        $client = $this->getMockClient(200);
24
        $adapter = $this->getAdapter($client);
25
        $adapter->request('DELETE', '/test.xml');
26
        $this->assertEmpty((string) $adapter->getLastRequest()->getBody());
27
    }
28
29
    public function testRequestWithHeadersWithoutBody()
30
    {
31
        $client = $this->getMockClient(200);
32
        $adapter = $this->getAdapter($client);
33
        $adapter->request('GET', '/test.xml', ['headers' => ['X-Test' => 'test']]);
34
        $this->assertArrayHasKey('X-Test', $adapter->getLastRequest()->getHeaders());
35
    }
36
37
    public function testInvalidRequestWithoutBody()
38
    {
39
        $this->expectException(RequestException::class);
40
        $client = $this->getMockClient(503);
41
        $adapter = $this->getAdapter($client);
42
        $adapter->request('DELETE', '/test.xml');
43
    }
44
45
    public function testGetClient()
46
    {
47
        $this->assertInstanceOf(Client::class, (new GuzzleAdapter('a', 'b'))->getClient());
48
    }
49
}
50