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
|
|
|
|