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

TestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMockClient() 0 7 1
A getAdapter() 0 5 1
A getMockResource() 0 5 1
A assertSameLastRequestUri() 0 3 1
1
<?php
2
3
namespace GuillermoandraeTest\Highrise;
4
5
use Guillermoandrae\Highrise\Http\GuzzleAdapter;
6
use Guillermoandrae\Highrise\Resources\ResourceFactory;
7
use Guillermoandrae\Highrise\Resources\ResourceInterface;
8
use GuzzleHttp\Client;
9
use GuzzleHttp\Handler\MockHandler;
10
use GuzzleHttp\HandlerStack;
11
use GuzzleHttp\Psr7\Response;
12
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
13
14
class TestCase extends PHPUnitTestCase
15
{
16
    protected function assertSameLastRequestUri(string $uri, ResourceInterface $resource)
17
    {
18
        $this->assertSame($uri, $resource->getAdapter()->getLastRequest()->getUri()->getPath());
19
    }
20
21
    protected function getMockResource(string $name, string $expectedBody)
22
    {
23
        $client = $this->getMockClient(200, [], $expectedBody);
24
        $adapter = $this->getAdapter($client);
25
        return ResourceFactory::factory($name, $adapter);
26
    }
27
28
    protected function getAdapter(Client $client): GuzzleAdapter
29
    {
30
        $adapter = new GuzzleAdapter('test', '123456');
31
        $adapter->setClient($client);
32
        return $adapter;
33
    }
34
35
    protected function getMockClient($expectedHttpStatusCode, array $expectedHeaders = [], $expectedBody = ''): Client
36
    {
37
        $mock = new MockHandler([
38
            new Response($expectedHttpStatusCode, $expectedHeaders, $expectedBody)
39
        ]);
40
        $handler = HandlerStack::create($mock);
41
        return new Client(['handler' => $handler]);
42
    }
43
}
44