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
|
|
|
/** @var mixed */ |
21
|
|
|
private $stream; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->stream = $this->mockStream(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testInterface() |
29
|
|
|
{ |
30
|
|
|
$this->assertInstanceOf('Graze\GuzzleHttp\JsonRpc\Message\RequestInterface', new Request('foo', 'bar')); |
31
|
|
|
$this->assertInstanceOf('Psr\Http\Message\RequestInterface', new Request('foo', 'bar')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function testGetRpcId() |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$request = new Request('foo', 'bar', [], json_encode([ |
37
|
|
|
'id' => 123 |
38
|
|
|
])); |
39
|
|
|
|
40
|
|
|
$this->assertEquals(123, $request->getRpcId()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetRpcIdIsNull() |
44
|
|
|
{ |
45
|
|
|
$request = new Request('foo', 'bar'); |
46
|
|
|
|
47
|
|
|
$this->assertNull($request->getRpcId()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function testGetRpcMethod() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$request = new Request('foo', 'bar', [], json_encode([ |
53
|
|
|
'method' => 'foo' |
54
|
|
|
])); |
55
|
|
|
|
56
|
|
|
$this->assertEquals('foo', $request->getRpcMethod()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testGetRpcMethodIsNull() |
60
|
|
|
{ |
61
|
|
|
$request = new Request('foo', 'bar'); |
62
|
|
|
|
63
|
|
|
$this->assertNull($request->getRpcMethod()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetRpcParams() |
67
|
|
|
{ |
68
|
|
|
$request = new Request('foo', 'bar', [], json_encode([ |
69
|
|
|
'params' => ['foo'=>'bar'] |
70
|
|
|
])); |
71
|
|
|
|
72
|
|
|
$this->assertEquals(['foo'=>'bar'], $request->getRpcParams()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetRpcParamsIsNull() |
76
|
|
|
{ |
77
|
|
|
$request = new Request('foo', 'bar'); |
78
|
|
|
|
79
|
|
|
$this->assertNull($request->getRpcParams()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function testGetRpcVersion() |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$request = new Request('foo', 'bar', [], json_encode([ |
85
|
|
|
'jsonrpc' => 'foo' |
86
|
|
|
])); |
87
|
|
|
|
88
|
|
|
$this->assertEquals('foo', $request->getRpcVersion()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testGetRpcVersionIsNull() |
92
|
|
|
{ |
93
|
|
|
$request = new Request('foo', 'bar'); |
94
|
|
|
|
95
|
|
|
$this->assertNull($request->getRpcVersion()); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.