public function testMultipleMixedRequests()
 {
     $handler = HandlerStack::create($this->getQueue());
     $this->client = new Client(['handler' => $handler]);
     $client = new JsonRpcClient($this->getClient(), new Uri('http://localhost/'));
     $request = new JsonRpcRequest('/test-request', [], $this->getRandomHash());
     $notification = new JsonRpcNotification('/test-notify', []);
     $error = new JsonRpcRequest('/test-error', [], $this->getRandomHash());
     $this->getQueue()->append(new Response(200, [], json_encode([['jsonrpc' => '2.0', 'id' => $request->getId(), 'result' => ['success' => true]], ['jsonrpc' => '2.0', 'id' => $error->getId(), 'error' => ['code' => JsonRpcErrorInterface::INTERNAL_ERROR, 'message' => 'Test error']]])));
     $calls = [$request, $notification, $error];
     $collection = $client->invoke($calls);
     $rResponse = $collection->getResponse($request);
     $nResponse = $collection->getResponse($notification);
     $eResponse = $collection->getResponse($error);
     self::assertNotNull($rResponse);
     self::assertInstanceOf(JsonRpcResponseInterface::class, $rResponse);
     self::assertTrue($rResponse->isSuccessful());
     self::assertObjectHasAttribute('success', $rResponse->getBody());
     self::assertTrue($rResponse->getBody()->success);
     self::assertNotNull($nResponse);
     self::assertInstanceOf(JsonRpcResponseInterface::class, $nResponse);
     self::assertTrue($nResponse->isSuccessful());
     self::assertNotNull($eResponse);
     self::assertInstanceOf(JsonRpcResponseInterface::class, $eResponse);
     self::assertFalse($eResponse->isSuccessful());
     self::assertInstanceOf(JsonRpcErrorInterface::class, $eResponse->getError());
     self::assertEquals('Test error', $eResponse->getError()->getMessage());
     self::assertEquals(JsonRpcErrorInterface::INTERNAL_ERROR, $eResponse->getError()->getCode());
 }
Exemplo n.º 2
0
 /**
  * @param RpcRequestInterface $call
  * @return JsonRpcRequest
  */
 private function transformCall(RpcRequestInterface $call)
 {
     $transformedCall = $call;
     if ($call instanceof RpcRequestInterface && !$call instanceof JsonRpcRequestInterface) {
         $transformedCall = JsonRpcRequest::fromRpcRequest($call, $this->idGenerator->getRequestIdentifier($call));
         return $transformedCall;
     }
     return $transformedCall;
 }