1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of Guzzle HTTP JSON-RPC |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @see http://github.com/graze/guzzle-jsonrpc/blob/master/LICENSE |
11
|
|
|
* @link http://github.com/graze/guzzle-jsonrpc |
12
|
|
|
*/ |
13
|
|
|
namespace Graze\GuzzleHttp\JsonRpc\Message; |
14
|
|
|
|
15
|
|
|
use Graze\GuzzleHttp\JsonRpc\ClientInterface; |
16
|
|
|
use Graze\GuzzleHttp\JsonRpc\Test\UnitTestCase; |
17
|
|
|
|
18
|
|
|
class RequestTest extends UnitTestCase |
19
|
|
|
{ |
20
|
|
|
public function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->stream = $this->mockStream(); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testInterface() |
26
|
|
|
{ |
27
|
|
|
$this->assertInstanceOf('Graze\GuzzleHttp\JsonRpc\Message\RequestInterface', new Request('foo', 'bar')); |
28
|
|
|
$this->assertInstanceOf('Psr\Http\Message\RequestInterface', new Request('foo', 'bar')); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function testGetRpcId() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$request = new Request('foo', 'bar', [], json_encode([ |
34
|
|
|
'id' => 123 |
35
|
|
|
])); |
36
|
|
|
|
37
|
|
|
$this->assertEquals(123, $request->getRpcId()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGetRpcIdIsNull() |
41
|
|
|
{ |
42
|
|
|
$request = new Request('foo', 'bar'); |
43
|
|
|
|
44
|
|
|
$this->assertNull($request->getRpcId()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function testGetRpcMethod() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$request = new Request('foo', 'bar', [], json_encode([ |
50
|
|
|
'method' => 'foo' |
51
|
|
|
])); |
52
|
|
|
|
53
|
|
|
$this->assertEquals('foo', $request->getRpcMethod()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testGetRpcMethodIsNull() |
57
|
|
|
{ |
58
|
|
|
$request = new Request('foo', 'bar'); |
59
|
|
|
|
60
|
|
|
$this->assertNull($request->getRpcMethod()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testGetRpcParams() |
64
|
|
|
{ |
65
|
|
|
$request = new Request('foo', 'bar', [], json_encode([ |
66
|
|
|
'params' => ['foo'=>'bar'] |
67
|
|
|
])); |
68
|
|
|
|
69
|
|
|
$this->assertEquals(['foo'=>'bar'], $request->getRpcParams()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testGetRpcParamsIsNull() |
73
|
|
|
{ |
74
|
|
|
$request = new Request('foo', 'bar'); |
75
|
|
|
|
76
|
|
|
$this->assertNull($request->getRpcParams()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
View Code Duplication |
public function testGetRpcVersion() |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$request = new Request('foo', 'bar', [], json_encode([ |
82
|
|
|
'jsonrpc' => 'foo' |
83
|
|
|
])); |
84
|
|
|
|
85
|
|
|
$this->assertEquals('foo', $request->getRpcVersion()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testGetRpcVersionIsNull() |
89
|
|
|
{ |
90
|
|
|
$request = new Request('foo', 'bar'); |
91
|
|
|
|
92
|
|
|
$this->assertNull($request->getRpcVersion()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: