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

JsonRpcTestCase::sendJsonRpcRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
crap 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