Exemple #1
0
 public function testHandleException()
 {
     ob_start();
     $this->server->handleException(new ParseError('something went wrong'));
     $ob = ob_get_clean();
     $output = JSON::decode($ob);
     $this->assertEquals(array('id' => null, 'jsonrpc' => '2.0', 'error' => array('code' => -32700, 'data' => 'something went wrong', 'message' => 'Parse error')), $output);
 }
 public function tearDown()
 {
     Server::$debug = $this->debug;
 }
    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);
    }
Exemple #4
0
<?php

use PG\JsonRpc\Server;
include __DIR__ . '/vendor/autoload.php';
$server = new Server();
$server->run();
Exemple #5
0
 public function setUp()
 {
     $this->app['logger'] = new Logger('phpunit', array(new NullHandler()));
     Server::$debug = true;
 }