Passed
Pull Request — master (#11)
by Pavel
06:35
created

JsonRpcTestCase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 43
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getKernelClass() 0 4 1
A sendRequest() 0 10 2
A sendJsonRpcRequest() 0 10 2
1
<?php
2
3
namespace Bankiru\Api\JsonRpc\Test\Tests;
4
5
use Bankiru\Api\BrowserKit\JsonRpcClient;
6
use Bankiru\Api\JsonRpc\Test\Kernel\TestKernel;
7
use ScayTrase\Api\IdGenerator\UuidGenerator;
8
use ScayTrase\Api\JsonRpc\JsonRpcResponseInterface;
9
use ScayTrase\Api\Rpc\RpcRequestInterface;
10
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
11
use Symfony\Component\HttpKernel\Client;
12
13
abstract class JsonRpcTestCase extends WebTestCase
14
{
15 1
    protected static function getKernelClass()
16
    {
17 1
        return TestKernel::class;
18
    }
19
20
    /**
21
     * @param        $endpoint
22
     * @param Client $client
23
     * @param        $requests
24
     *
25
     * @return null|\Symfony\Component\HttpFoundation\Response
26
     */
27 11
    protected function sendRequest(Client $client = null, $endpoint, $requests)
28
    {
29 11
        if (null === $client) {
30
            $client = static::createClient();
31
        }
32
33 11
        $client->request('POST', $endpoint, [], [], [], json_encode($requests));
34
35 7
        return $client->getResponse();
36
    }
37
38
    /**
39
     * @param RpcRequestInterface $request
40
     * @param string              $endpoint
41
     * @param Client|null         $client
42
     *
43
     * @return JsonRpcResponseInterface
44
     */
45 2
    protected function sendJsonRpcRequest(RpcRequestInterface $request, $endpoint, Client $client = null)
46
    {
47 2
        if (null === $client) {
48 2
            $client = static::createClient();
49 2
        }
50
51 2
        $jsonRpcClient = new JsonRpcClient($client, $endpoint, new UuidGenerator());
52
53 2
        return $jsonRpcClient->invoke($request)->getResponse($request);
54
    }
55
}
56