1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Vectorface\SnappyRouterTests\Request; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Vectorface\SnappyRouter\Request\JsonRpcRequest; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Tests the JsonRpcRequest class. |
10
|
|
|
* |
11
|
|
|
* @copyright Copyright (c) 2014, VectorFace, Inc. |
12
|
|
|
*/ |
13
|
|
|
class JsonRpcRequestTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* An overview of how to use the JsonRpcRequest class. |
17
|
|
|
* @test |
18
|
|
|
*/ |
19
|
|
|
public function synopsis() |
20
|
|
|
{ |
21
|
|
|
/* Handles JSON-RPC 1.0 requests. */ |
22
|
|
|
$request = new JsonRpcRequest('MyService', (object)array( |
23
|
|
|
'method' => 'remoteProcedure', |
24
|
|
|
'params' => array(1, 2, 3), |
25
|
|
|
'id' => 'uniqueidentifier' |
26
|
|
|
)); |
27
|
|
|
|
28
|
|
|
$this->assertEquals('POST', $request->getVerb()); |
29
|
|
|
$this->assertEquals('remoteProcedure', $request->getMethod()); |
30
|
|
|
$this->assertEquals('1.0', $request->getVersion()); |
31
|
|
|
$this->assertEquals(array(1, 2, 3), $request->getParameters()); |
32
|
|
|
$this->assertEquals('uniqueidentifier', $request->getIdentifier()); |
33
|
|
|
$this->assertNull($request->getPost('anything')); // Post should be ignored. |
34
|
|
|
|
35
|
|
|
/* Handles JSON-RPC 2.0 requests. */ |
36
|
|
|
$request = new JsonRpcRequest('MyService', (object)array( |
37
|
|
|
'jsonrpc' => '2.0', |
38
|
|
|
'method' => 'remoteProcedure', |
39
|
|
|
'id' => 'uniqueidentifier' |
40
|
|
|
)); |
41
|
|
|
|
42
|
|
|
$this->assertEquals('2.0', $request->getVersion()); |
43
|
|
|
$this->assertEquals(array(), $request->getParameters()); |
44
|
|
|
|
45
|
|
|
/* Catches invalid request format. */ |
46
|
|
|
$request = new JsonRpcRequest('MyService', (object)array( |
47
|
|
|
'jsonrpc' => '2.0', |
48
|
|
|
'method' => null |
49
|
|
|
)); |
50
|
|
|
$this->assertFalse($request->isValid()); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|