/** * @expectedException InvalidArgumentException */ public function testNotEnoughArguments() { $server = new Server(); $server->bind('getAllC', new B(), 'getAll'); $server->executeProcedure('getAllC'); }
<?php namespace StemMajzel\MSISDNInfo; require 'MSISDNInfo.php'; require 'vendor/autoload.php'; use JsonRPC\Server as RPCServer; class MSISDNInfoServer extends MSISDNInfo { public function MSISDNLookup($number) { return $this->lookupMSISDN($number); } } $server = new RPCServer(); $server->bind('MSISDNLookup', new MSISDNInfoServer(), 'MSISDNLookup'); echo $server->execute();
public function testBatchOk() { $server = new Server('[ {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"}, {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]}, {"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"}, {"foo": "boo"}, {"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"}, {"jsonrpc": "2.0", "method": "get_data", "id": "9"}, {"jsonrpc": "2.0", "method": "doSomething", "id": 10}, {"jsonrpc": "2.0", "method": "doStuff", "id": 15} ]'); $server->register('sum', function ($a, $b, $c) { return $a + $b + $c; }); $server->register('subtract', function ($minuend, $subtrahend) { return $minuend - $subtrahend; }); $server->register('get_data', function () { return array('hello', 5); }); $server->attach(new C()); $server->bind('doStuff', 'C', 'doSomething'); $response = $server->execute(); $this->assertEquals(json_decode('[ {"jsonrpc": "2.0", "result": 7, "id": "1"}, {"jsonrpc": "2.0", "result": 19, "id": "2"}, {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}, "id": null}, {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": "5"}, {"jsonrpc": "2.0", "result": ["hello", 5], "id": "9"}, {"jsonrpc": "2.0", "result": "something", "id": "10"}, {"jsonrpc": "2.0", "result": "something", "id": "15"} ]', true), json_decode($response, true)); }