AbstractRequestTest::getHttpClient()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Paytic\Omnipay\Paylike\Tests\Message;
4
5
//use Paytic\Omnipay\Paylike\Tests\Traits\HasTestUtilMethods;
6
use Paytic\Omnipay\Paylike\Message\AbstractRequest;
7
use Paytic\Omnipay\Paylike\Tests\AbstractTest;
8
use Http\Mock\Client as MockClient;
9
use Omnipay\Common\Http\Client;
10
use Omnipay\Common\Http\ClientInterface;
11
use Symfony\Component\HttpFoundation\Request as HttpRequest;
12
13
/**
14
 * Class AbstractRequestTest
15
 * @package Paytic\Omnipay\Paylike\Tests\Message
16
 */
17
abstract class AbstractRequestTest extends AbstractTest
18
{
19
    /** @var ClientInterface */
20
    private $httpClient;
21
22
    /** @var  MockClient */
23
    private $mockClient;
24
25
    /**
26
     * @param string $class
27
     * @param array $data
28
     * @return AbstractRequest
29
     */
30
    protected function newRequestWithInitTest($class, $data)
31
    {
32
        $request = $this->newRequest($class);
33
        self::assertInstanceOf($class, $request);
34
        $request->initialize($data);
35
        return $request;
36
    }
37
38
    /**
39
     * @param string $class
40
     * @return AbstractRequest
41
     */
42
    protected function newRequest($class)
43
    {
44
        $client = $this->getHttpClient();
45
        $request = HttpRequest::createFromGlobals();
46
        $request = new $class($client, $request);
47
        return $request;
48
    }
49
50
    public function getHttpClient()
51
    {
52
        if (null === $this->httpClient) {
53
            $this->httpClient = new Client(
54
                $this->getMockClient()
55
            );
56
        }
57
58
        return $this->httpClient;
59
    }
60
61
    public function getMockClient()
62
    {
63
        if (null === $this->mockClient) {
64
            $this->mockClient = new MockClient();
65
        }
66
67
        return $this->mockClient;
68
    }
69
}
70