1 | <?php |
||
23 | class JsonRpcClientTest extends AbstractJsonRpcClientTest |
||
24 | { |
||
25 | public function paramsProvider() |
||
35 | |||
36 | /** |
||
37 | * @dataProvider paramsProvider |
||
38 | * @param $params |
||
39 | */ |
||
40 | 5 | public function testSingleRequestFormatting($params) |
|
45 | |||
46 | /** |
||
47 | * @param mixed $params |
||
48 | * @param bool $isArray |
||
49 | * @return JsonRpcClient |
||
50 | */ |
||
51 | 10 | private function getProphetClient($params, $isArray) |
|
52 | 2 | { |
|
53 | 10 | $guzzle = $this->prophesize(ClientInterface::class); |
|
54 | 10 | $self = $this; |
|
55 | 10 | $guzzle->sendAsync(Argument::type(RequestInterface::class))->will( |
|
56 | function ($args) use ($self, $params, $isArray) { |
||
57 | /** @var RequestInterface $request */ |
||
58 | 10 | $request = $args[0]; |
|
59 | 10 | $content = $request->getBody()->getContents(); |
|
60 | 10 | $data = json_decode($content); |
|
61 | 10 | if ($isArray) { |
|
62 | 5 | $self::assertTrue(is_array($data)); |
|
63 | 5 | $self::assertNotEmpty($data); |
|
64 | 5 | $data = array_shift($data); |
|
65 | 5 | } |
|
66 | 10 | $self::assertEquals(JSON_ERROR_NONE, json_last_error()); |
|
67 | 10 | $self::assertObjectHasAttribute('id', $data); |
|
68 | 10 | $self::assertObjectHasAttribute('method', $data); |
|
69 | 10 | $self::assertObjectHasAttribute('params', $data); |
|
70 | 10 | $self::assertObjectHasAttribute('jsonrpc', $data); |
|
71 | 10 | $self::assertEquals('test', $data->id); |
|
72 | 10 | $self::assertEquals('2.0', $data->jsonrpc); |
|
73 | 10 | $self::assertEquals('test', $data->method); |
|
74 | 10 | $self::assertEquals($params, $data->params); |
|
75 | |||
76 | 10 | return new Promise( |
|
77 | function () { |
||
78 | 10 | }, |
|
79 | function () { |
||
80 | } |
||
81 | 10 | ); |
|
82 | } |
||
83 | 10 | ); |
|
84 | |||
85 | 10 | return new JsonRpcClient($guzzle->reveal(), new Uri('http://localhost/')); |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * @dataProvider paramsProvider |
||
90 | * @param $params |
||
91 | */ |
||
92 | 5 | public function testBatchRequestFormatting($params) |
|
97 | |||
98 | 1 | public function testSingleSuccessfulRequest() |
|
114 | |||
115 | 2 | public function testSingleFailedRequest() |
|
116 | 1 | { |
|
117 | 2 | $client = new JsonRpcClient($this->getClient(), new Uri('http://localhost/')); |
|
118 | |||
119 | 1 | $request = $this->createRequestForSingleInvocation('/test', ['parameter' => 'test'], new JsonRpcError(JsonRpcErrorInterface::INTERNAL_ERROR, 'Test error')); |
|
120 | 1 | $collection = $client->invoke([$request]); |
|
121 | |||
122 | /** @var JsonRpcResponseInterface $response */ |
||
123 | 1 | $response = $collection->getResponse($request); |
|
124 | 1 | self::assertFalse($response->isSuccessful()); |
|
125 | 1 | self::assertNull($response->getBody()); |
|
126 | 1 | self::assertNotNull($response->getError()); |
|
127 | 1 | self::assertEquals($client::VERSION, $response->getVersion()); |
|
128 | 1 | self::assertInstanceOf(RpcErrorInterface::class, $response->getError()); |
|
129 | 1 | self::assertEquals(JsonRpcErrorInterface::INTERNAL_ERROR, $response->getError()->getCode()); |
|
130 | 1 | self::assertEquals('Test error', $response->getError()->getMessage()); |
|
131 | 1 | } |
|
132 | |||
133 | 1 | public function testSingleNotification() |
|
146 | |||
147 | 1 | public function testMultipleMixedRequests() |
|
189 | |||
190 | /** @expectedException \GuzzleHttp\Exception\GuzzleException */ |
||
191 | 1 | public function testFailedCall() |
|
199 | } |
||
200 |