<?php require '../../lib/server.php'; $methods = array('subtract' => function ($a, $b) { return $a - $b; }, 'subtractNamed' => function ($params) { return $params['minuend'] - $params['subtrahend']; }); $server = new Callchedan\Server($methods); echo $server->handle();
public function testCallInvalidJSONRPC() { $server = new Callchedan\Server(array()); $this->assertEquals('[{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid Request","data":"Not an array"}},{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid Request","data":"Not an array"}},{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid Request","data":"Not an array"}}]', $server->handle('[1,2,3]')); $this->assertEquals('{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid Request","data":"Invalid method"}}', $server->handle('{"jsonrpc": "2.0", "method": 1, "params": "bar"}')); }