Ejemplo n.º 1
0
 /**
  * @covers \PG\JsonRpc\Server::handle
  */
 public function testIdIsPreserved()
 {
     $this->server->expose('Sample', 'PG\\JsonRpc\\tests\\sample\\Sample');
     $request = Request::create('', 'POST', array(), array(), array(), array(), '[{"jsonrpc":"2.0","id":1,"method":"Sample.divide","params": [10, 5]},
          {"jsonrpc":"2.0","id":"fourteen","method":"Sample.divide","params": [11, 5]}]');
     $response = $this->server->handle($request);
     $result = JSON::decode($response->getContent());
     $this->assertEquals(array(array('jsonrpc' => '2.0', 'id' => 1, 'result' => 10 / 5), array('jsonrpc' => '2.0', 'id' => 'fourteen', 'result' => 11 / 5)), $result);
 }
Ejemplo n.º 2
0
    public function testNotificationInBatchRequest()
    {
        $server = new Server();
        $server->expose('Sample', 'PG\\JsonRpc\\tests\\sample\\Sample');
        $body = <<<JSON
[
{"jsonrpc": "2.0", "method": "Sample.divide", "params": [10, 0], "id":1},
{"jsonrpc": "2.0", "method": "Sample.divide", "params": [10, 5], "id":2},
{"jsonrpc": "2.0", "method": "Sample.divide", "params": [10, 5]},
{"jsonrpc": "2.0", "method": "Sample.divide", "params": [10, 0]},
{"jsonrpc": "2.0", "method": "Sample.divide", "params": [10, 5], "id":3}
]
JSON;
        $expected = <<<JSON
[{"id":1,"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params"}},{"jsonrpc":"2.0","result":2,"id":2},{"jsonrpc":"2.0","result":2,"id":3}]
JSON;
        $request = Request::create('', 'POST', array(), array(), array(), array(), $body);
        $response = $server->handle($request);
        $this->assertJSONEquals($response->getContent(), $expected);
    }