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

TestBase   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 1
c 3
b 0
f 2
lcom 0
cbo 3
dl 0
loc 16
rs 10
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