コード例 #1
0
 public function testParameterTypes(array $arg1, \stdClass $arg2, Testparameter $arg3)
 {
     if (!is_array($arg1)) {
         throw new \InvalidArgumentException('arg1 must be an array!');
     }
     if (!is_object($arg2)) {
         throw new \InvalidArgumentException('arg2 must be an object!');
     }
     if (!$arg3 instanceof Testparameter) {
         throw new \InvalidArgumentException('arg2 must be an object!');
     }
     return $arg3->getA() . $arg3->getB() . $arg3->getC();
 }
コード例 #2
0
 public function testParameters()
 {
     // params as associative array in right order
     $controller = $this->kernel->getContainer()->get('wa72_jsonrpc.jsonrpccontroller');
     $requestdata = array('jsonrpc' => '2.0', 'id' => 'parametertest', 'method' => 'wa72_jsonrpc.testservice:parametertest', 'params' => array('arg1' => 'abc', 'arg2' => 'def', 'arg_array' => array()));
     $response = $this->makeRequest($controller, $requestdata);
     $this->assertArrayNotHasKey('error', $response);
     $this->assertArrayHasKey('result', $response);
     $this->assertEquals('abcdef', $response['result']);
     // params as simple array in right order
     $controller = $this->kernel->getContainer()->get('wa72_jsonrpc.jsonrpccontroller');
     $requestdata = array('jsonrpc' => '2.0', 'id' => 'parametertest', 'method' => 'wa72_jsonrpc.testservice:parametertest', 'params' => array('abc', 'def', array()));
     $response = $this->makeRequest($controller, $requestdata);
     $this->assertArrayNotHasKey('error', $response);
     $this->assertArrayHasKey('result', $response);
     $this->assertEquals('abcdef', $response['result']);
     // params as associative array in mixed order
     $controller = $this->kernel->getContainer()->get('wa72_jsonrpc.jsonrpccontroller');
     $requestdata = array('jsonrpc' => '2.0', 'id' => 'parametertest', 'method' => 'wa72_jsonrpc.testservice:parametertest', 'params' => array('arg_array' => array(), 'arg2' => 'def', 'arg1' => 'abc'));
     $response = $this->makeRequest($controller, $requestdata);
     $this->assertArrayNotHasKey('error', $response);
     $this->assertArrayHasKey('result', $response);
     $this->assertEquals('abcdef', $response['result']);
     // params with objects
     $controller = $this->kernel->getContainer()->get('wa72_jsonrpc.jsonrpccontroller');
     $arg3 = new Testparameter('abc');
     $arg3->setB('def');
     $arg3->setC('ghi');
     $requestdata = array('jsonrpc' => '2.0', 'id' => 'testParameterTypes', 'method' => 'wa72_jsonrpc.testservice:testParameterTypes', 'params' => array('arg1' => array(), 'arg2' => new \stdClass(), 'arg3' => $arg3));
     $response = $this->makeRequest($controller, $requestdata);
     $this->assertArrayNotHasKey('error', $response);
     $this->assertArrayHasKey('result', $response);
     $this->assertEquals('abcdefghi', $response['result']);
 }