Passed
Pull Request — master (#30)
by Daniel
03:08
created

TestBase::getClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Sainsburys\Guzzle\Oauth2\Tests;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\ClientInterface;
7
use GuzzleHttp\HandlerStack;
8
9
abstract class TestBase extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var ClientInterface
13
     */
14
    protected $client;
15
16
    /**
17
     * @var MockOAuth2Server
18
     */
19
    protected $server;
20
21
    /**
22
     * @param array $options
23
     * @param array $serverOptions
24
     *
25
     * @return ClientInterface
26
     */
27
    protected function createClient(array $options = [], array $serverOptions = [])
28
    {
29
        $this->server = new MockOAuth2Server($serverOptions);
30
        $this->client = new Client([
31
                'handler' => $this->server->getHandlerStack()
32
            ] + $options);
33
34
        return $this->client;
35
    }
36
37
    /**
38
     * @return ClientInterface|null
39
     */
40
    protected function getClient()
41
    {
42
        return $this->client;
43
    }
44
45
    /**
46
     * @return HandlerStack|null
47
     */
48
    protected function getHandlerStack()
49
    {
50
        if ($this->server instanceof MockOAuth2Server) {
51
            return $this->server->getHandlerStack();
52
        }
53
54
        return null;
55
    }
56
}
57