From a491348d442ab8e6cd2fa403d4365cdad78e52ce Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 21 Jun 2018 14:13:41 -0700 Subject: Vendoring deprecated composer libs --- libs/jsonrpc/tests/Response/ResponseParserTest.php | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 libs/jsonrpc/tests/Response/ResponseParserTest.php (limited to 'libs/jsonrpc/tests/Response/ResponseParserTest.php') diff --git a/libs/jsonrpc/tests/Response/ResponseParserTest.php b/libs/jsonrpc/tests/Response/ResponseParserTest.php new file mode 100644 index 00000000..f195014f --- /dev/null +++ b/libs/jsonrpc/tests/Response/ResponseParserTest.php @@ -0,0 +1,100 @@ +withPayload(json_decode('{"jsonrpc": "2.0", "result": "foobar", "id": "1"}', true)) + ->parse(); + + $this->assertEquals('foobar', $result); + } + + public function testWithBadJsonFormat() + { + $this->setExpectedException('\JsonRPC\Exception\InvalidJsonFormatException'); + + ResponseParser::create() + ->withPayload('foobar') + ->parse(); + } + + public function testWithBadProcedure() + { + $this->setExpectedException('BadFunctionCallException'); + + ResponseParser::create() + ->withPayload(json_decode('{"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": "1"}', true)) + ->parse(); + } + + public function testWithInvalidArgs() + { + $this->setExpectedException('InvalidArgumentException'); + + ResponseParser::create() + ->withPayload(json_decode('{"jsonrpc": "2.0", "error": {"code": -32602, "message": "Invalid params"}, "id": "1"}', true)) + ->parse(); + } + + public function testWithInvalidRequest() + { + $this->setExpectedException('\JsonRPC\Exception\InvalidJsonRpcFormatException'); + + ResponseParser::create() + ->withPayload(json_decode('{"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}, "id": null}', true)) + ->parse(); + } + + public function testWithParseError() + { + $this->setExpectedException('\JsonRPC\Exception\InvalidJsonFormatException'); + + ResponseParser::create() + ->withPayload(json_decode('{"jsonrpc": "2.0", "error": {"code": -32700, "message": "Parse error"}, "id": null}', true)) + ->parse(); + } + + public function testWithOtherError() + { + $this->setExpectedException('\JsonRPC\Exception\ResponseException'); + + ResponseParser::create() + ->withPayload(json_decode('{"jsonrpc": "2.0", "error": {"code": 42, "message": "Something", "data": "foobar"}, "id": null}', true)) + ->parse(); + } + + public function testBatch() + { + $payload = '[ + {"jsonrpc": "2.0", "result": 7, "id": "1"}, + {"jsonrpc": "2.0", "result": 19, "id": "2"} + ]'; + + $result = ResponseParser::create() + ->withPayload(json_decode($payload, true)) + ->parse(); + + $this->assertEquals(array(7, 19), $result); + } + + public function testBatchWithError() + { + $payload = '[ + {"jsonrpc": "2.0", "result": 7, "id": "1"}, + {"jsonrpc": "2.0", "result": 19, "id": "2"}, + {"jsonrpc": "2.0", "error": {"code": -32602, "message": "Invalid params"}, "id": "1"} + ]'; + + $this->setExpectedException('InvalidArgumentException'); + + ResponseParser::create() + ->withPayload(json_decode($payload, true)) + ->parse(); + } +} -- cgit v1.2.3