/** * @return array */ public function providerTestFromArray() { $minimal = new Request(); $minimal->setMethod('a'); $withId = clone $minimal; $withId->setId(3); $withData = clone $withId; $withData->setParams(array('x')); return array('Missing version' => array(array('hello' => 1), 'Request is not valid JsonRPC request: missing protocol version'), 'Invalid version' => array(array('jsonrpc' => 1), 'Request is not valid JsonRPC request: invalid protocol version'), 'Missing method' => array(array('jsonrpc' => 2.0, 'No method'), 'Request is not valid JsonRPC request: missing method'), 'Minimal data' => array(array('jsonrpc' => 2.0, 'method' => 'a'), false, $minimal), 'Data with id' => array(array('jsonrpc' => 2.0, 'method' => 'a', 'id' => 3), false, $withId), 'Data with params' => array(array('jsonrpc' => 2.0, 'method' => 'a', 'id' => 3, 'params' => array('x')), false, $withData)); }
/** * @return array */ public function providerTestBatch() { $request = new Request(); $request->setMethod('testMethod'); return array('Empty request' => array(array(), false), 'Invalid request' => array(array($request, '123'), false), 'Valid request' => array(array($request), true)); }
/** * @covers \Moaction\Jsonrpc\Server\BasicServer::singleCall * @dataProvider providerTestExceptionCall */ public function testExceptionCall($exception, $expected) { $server = new BasicServer(); $reflectionObj = new ReflectionObject($server); $reflectionMethod = $reflectionObj->getMethod('singleCall'); $reflectionMethod->setAccessible(true); /** @var PHPUnit_Framework_MockObject_MockObject|ServerMethod $method */ $method = $this->getMockBuilder('\\Moaction\\Jsonrpc\\Server\\ServerMethod')->disableOriginalConstructor()->setMethods(array('call'))->getMock(); $method->expects($this->any())->method('call')->will($this->throwException($exception)); $server->addMethod('test', $method); $request = new Request(); $request->setMethod('test'); $result = $reflectionMethod->invoke($server, $request); $this->assertEquals($expected, $result); }