From 297db091f7e4bad8fd6993238be3b771301148b6 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Wed, 7 Feb 2018 15:00:11 +0800 Subject: [PATCH] Add json rp method tests. --- test/unit/JSONRPCTest.php | 81 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 test/unit/JSONRPCTest.php diff --git a/test/unit/JSONRPCTest.php b/test/unit/JSONRPCTest.php new file mode 100644 index 0000000..a3592c5 --- /dev/null +++ b/test/unit/JSONRPCTest.php @@ -0,0 +1,81 @@ +id = $id; + + $this->assertEquals($id, $rpc->id); + $this->assertEquals('2.0', $rpc->rpcVersion); + $this->assertEquals($method, $rpc->method); + $this->assertEquals($params, $rpc->arguments); + $this->assertEquals([ + 'id' => $id, + 'jsonrpc' => '2.0', + 'method' => $method, + 'params' => $params + ], $rpc->toPayload()); + $this->assertEquals(json_encode($rpc->toPayload()), (string) $rpc); + + $params = [ + 'hello ethereum' + ]; + $rpc->arguments = $params; + + $this->assertEquals($params, $rpc->arguments); + $this->assertEquals([ + 'id' => $id, + 'jsonrpc' => '2.0', + 'method' => $method, + 'params' => $params + ], $rpc->toPayload()); + $this->assertEquals(json_encode($rpc->toPayload()), (string) $rpc); + } + + /** + * testThrowException + * + * @return void + */ + public function testThrowException() + { + $id = 'zzz'; + $params = [ + 'hello world' + ]; + $method = 'echo'; + $rpc = new JSONRPC($method, $params); + + try { + // id is not integer + $rpc->id = $id; + } catch (InvalidArgumentException $e) { + $this->assertTrue($e !== null); + } + + try { + // arguments is not array + $rpc->arguments = $id; + } catch (InvalidArgumentException $e) { + $this->assertTrue($e !== null); + } + } +} \ No newline at end of file