Passed
Pull Request — master (#339)
by Alejandro
05:38
created

ApiTestCase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A callApi() 0 3 1
A setApiClient() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\ApiTest;
5
6
use Fig\Http\Message\RequestMethodInterface;
7
use Fig\Http\Message\StatusCodeInterface;
8
use GuzzleHttp\ClientInterface;
9
use PHPUnit\Framework\TestCase;
10
use Psr\Http\Message\ResponseInterface;
11
use function sprintf;
12
13
abstract class ApiTestCase extends TestCase implements StatusCodeInterface, RequestMethodInterface
14
{
15
    private const PATH_PREFX = '/rest/v1';
16
17
    /** @var ClientInterface */
18
    private static $client;
19
20
    public static function setApiClient(ClientInterface $client): void
21
    {
22
        self::$client = $client;
23
    }
24
25
    /**
26
     * @throws \GuzzleHttp\Exception\GuzzleException
27
     */
28
    protected function callApi(string $method, string $uri, array $options = []): ResponseInterface
29
    {
30
        return self::$client->request($method, sprintf('%s%s', self::PATH_PREFX, $uri), $options);
31
    }
32
}
33