/**
  * @return array
  */
 public function providerTestToArray()
 {
     $response = new Response();
     $response->setId(1);
     $response->setResult('result 1');
     $errorResponse = new Response();
     $errorResponse->setId(1);
     $errorResponse->setError(new Error());
     $nullIdError = new Response();
     $nullIdError->setError(new Error(Error::ERROR_PARSE_ERROR));
     return array(array($response, array('jsonrpc' => Request::VERSION, 'id' => 1, 'result' => 'result 1')), array($errorResponse, array('jsonrpc' => Request::VERSION, 'id' => 1, 'error' => array('code' => Error::ERROR_SERVER_ERROR, 'message' => 'Server error'))), array($nullIdError, array('jsonrpc' => Request::VERSION, 'id' => null, 'error' => array('code' => Error::ERROR_PARSE_ERROR, 'message' => 'Parse error'))));
 }
 /**
  * @param string $message
  * @param int $id
  * @param int $code
  * @param mixed $data
  * @return Response
  */
 protected function createErrorResponse($code, $message = null, $id = null, $data = null)
 {
     $response = new Response();
     $response->setError(new Error($code, $message, $data));
     $response->setId($id);
     return $response;
 }
 public function providerTestPrepareBatchResponse()
 {
     $response1 = new Response();
     $response1->setId(4);
     $response2 = new Response();
     $response2->setId(7);
     $expected = array(4 => $response1, 7 => $response2);
     return array('Invalid json' => array('{}invalid', false), 'Unexpected response' => array('{"id":1}', false), 'Multi response' => array('[{"id": 4}, {"id": 7}]', $expected));
 }
 /**
  * @covers \Moaction\Jsonrpc\Server\BasicServer::batchCall
  */
 public function testBatchCall()
 {
     $batchRequest = array(array('jsonrpc' => 2.0, 'method' => 'test', 'id' => 1), array('jsonrpc' => 2.0, 'method' => 'test2', 'id' => 2), array('method' => 'test3', 'id' => 2), array('jsonrpc' => 2.0, 'method' => 'notification'));
     $response1 = new Response();
     $response1->setResult('method result');
     $response1->setId(1);
     $response2 = new Response();
     $response2->setError(new Error(Error::ERROR_METHOD_NOT_FOUND, null, array('method' => 'test2')));
     $response2->setId(2);
     $response3 = new Response();
     $response3->setError(new Error(Error::ERROR_INVALID_REQUEST, 'Request is not valid JsonRPC request: missing protocol version'));
     $server = new BasicServer();
     $server->addMethod('test', function () {
         return 'method result';
     });
     $server->addMethod('notification', function () {
     });
     $reflectionObj = new ReflectionObject($server);
     $reflectionMethod = $reflectionObj->getMethod('batchCall');
     $reflectionMethod->setAccessible(true);
     $result = $reflectionMethod->invoke($server, $batchRequest);
     $this->assertCount(3, $result);
     $this->assertEquals($response1, $result[0]);
     $this->assertEquals($response2, $result[1]);
     $this->assertEquals($response3, $result[2]);
 }