diff options
author | Frédéric Guillot <fred@kanboard.net> | 2018-06-21 14:13:41 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2018-06-21 14:13:41 -0700 |
commit | a491348d442ab8e6cd2fa403d4365cdad78e52ce (patch) | |
tree | a00f575d82afb2c9051bad95398b4250f4a3d44d /libs/jsonrpc/tests/Response/ResponseParserTest.php | |
parent | c73ac5f1f818b6b21083f6785b4b2f6d778a6496 (diff) |
Vendoring deprecated composer libs
Diffstat (limited to 'libs/jsonrpc/tests/Response/ResponseParserTest.php')
-rw-r--r-- | libs/jsonrpc/tests/Response/ResponseParserTest.php | 100 |
1 files changed, 100 insertions, 0 deletions
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 @@ +<?php + +use JsonRPC\Response\ResponseParser; + +require_once __DIR__.'/../../../../vendor/autoload.php'; + +class ResponseParserTest extends PHPUnit_Framework_TestCase +{ + public function testSingleRequest() + { + $result = ResponseParser::create() + ->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(); + } +} |