Ejemplo n.º 1
0
 /**
  * @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));
 }
Ejemplo n.º 2
0
 /**
  * @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));
 }
Ejemplo n.º 3
0
 /**
  * @param array $params
  * @return Request
  */
 protected function getRequest(array $params)
 {
     return Request::fromArray($params);
 }
Ejemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function call(Request $request)
 {
     $data = json_encode($request->toArray());
     $result = $this->send($data);
     return $this->prepareResponse($result);
 }
Ejemplo n.º 5
0
 /**
  * @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);
 }