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/ClientTest.php | |
parent | c73ac5f1f818b6b21083f6785b4b2f6d778a6496 (diff) |
Vendoring deprecated composer libs
Diffstat (limited to 'libs/jsonrpc/tests/ClientTest.php')
-rw-r--r-- | libs/jsonrpc/tests/ClientTest.php | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/libs/jsonrpc/tests/ClientTest.php b/libs/jsonrpc/tests/ClientTest.php new file mode 100644 index 00000000..d1f83877 --- /dev/null +++ b/libs/jsonrpc/tests/ClientTest.php @@ -0,0 +1,103 @@ +<?php + +use JsonRPC\Client; + +require_once __DIR__.'/../../../vendor/autoload.php'; + +class ClientTest extends PHPUnit_Framework_TestCase +{ + private $httpClient; + + public function setUp() + { + $this->httpClient = $this + ->getMockBuilder('\JsonRPC\HttpClient') + ->setMethods(array('execute')) + ->getMock(); + } + + public function testSendBatch() + { + $client = new Client('', false, $this->httpClient); + $response = array( + array( + 'jsonrpc' => '2.0', + 'result' => 'c', + 'id' => 1, + ), + array( + 'jsonrpc' => '2.0', + 'result' => 'd', + 'id' => 2, + ) + ); + + $this->httpClient + ->expects($this->once()) + ->method('execute') + ->with($this->stringContains('[{"jsonrpc":"2.0","method":"methodA","id":')) + ->will($this->returnValue($response)); + + + $result = $client->batch() + ->execute('methodA', array('a' => 'b')) + ->execute('methodB', array('a' => 'b')) + ->send(); + + $this->assertEquals(array('c', 'd'), $result); + } + + public function testSendRequest() + { + $client = new Client('', false, $this->httpClient); + + $this->httpClient + ->expects($this->once()) + ->method('execute') + ->with($this->stringContains('{"jsonrpc":"2.0","method":"methodA","id":')) + ->will($this->returnValue(array('jsonrpc' => '2.0', 'result' => 'foobar', 'id' => 1))); + + $result = $client->execute('methodA', array('a' => 'b')); + $this->assertEquals($result, 'foobar'); + } + + public function testSendRequestWithError() + { + $client = new Client('', false, $this->httpClient); + + $this->httpClient + ->expects($this->once()) + ->method('execute') + ->with($this->stringContains('{"jsonrpc":"2.0","method":"methodA","id":')) + ->will($this->returnValue(array( + 'jsonrpc' => '2.0', + 'error' => array( + 'code' => -32601, + 'message' => 'Method not found', + ), + ))); + + $this->setExpectedException('BadFunctionCallException'); + $client->execute('methodA', array('a' => 'b')); + } + + public function testSendRequestWithErrorAndReturnExceptionEnabled() + { + $client = new Client('', true, $this->httpClient); + + $this->httpClient + ->expects($this->once()) + ->method('execute') + ->with($this->stringContains('{"jsonrpc":"2.0","method":"methodA","id":')) + ->will($this->returnValue(array( + 'jsonrpc' => '2.0', + 'error' => array( + 'code' => -32601, + 'message' => 'Method not found', + ), + ))); + + $result = $client->execute('methodA', array('a' => 'b')); + $this->assertInstanceOf('BadFunctionCallException', $result); + } +} |