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 ResponseTest 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\ResponseInterface', new Response(200)); |
31
|
|
|
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', new Response(200)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testGetRpcId() |
35
|
|
|
{ |
36
|
|
|
$response = new Response(200, [], json_encode([ |
37
|
|
|
'id' => 123 |
38
|
|
|
])); |
39
|
|
|
|
40
|
|
|
$this->assertEquals(123, $response->getRpcId()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testGetRpcIdIsNull() |
44
|
|
|
{ |
45
|
|
|
$response = new Response(200); |
46
|
|
|
|
47
|
|
|
$this->assertNull($response->getRpcId()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function testGetRpcErrorCode() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$response = new Response(200, [], json_encode([ |
53
|
|
|
'error' => ['code'=>123] |
54
|
|
|
])); |
55
|
|
|
|
56
|
|
|
$this->assertEquals(123, $response->getRpcErrorCode()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testGetRpcErrorCodeIsNull() |
60
|
|
|
{ |
61
|
|
|
$response = new Response(200); |
62
|
|
|
|
63
|
|
|
$this->assertNull($response->getRpcErrorCode()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetRpcErrorMessage() |
67
|
|
|
{ |
68
|
|
|
$response = new Response(200, [], json_encode([ |
69
|
|
|
'error' => ['message'=>'foo'] |
70
|
|
|
])); |
71
|
|
|
|
72
|
|
|
$this->assertEquals('foo', $response->getRpcErrorMessage()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetRpcErrorMessageIsNull() |
76
|
|
|
{ |
77
|
|
|
$response = new Response(200); |
78
|
|
|
|
79
|
|
|
$this->assertNull($response->getRpcErrorMessage()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function testGetRpcErrorData() |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$response = new Response(200, [], json_encode([ |
85
|
|
|
'error' => ['data' => []] |
86
|
|
|
])); |
87
|
|
|
|
88
|
|
|
$this->assertEquals([], $response->getRpcErrorData()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testGetRpcErrorDataIsNull() |
92
|
|
|
{ |
93
|
|
|
$response = new Response(200); |
94
|
|
|
|
95
|
|
|
$this->assertNull($response->getRpcErrorData()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testGetRpcResult() |
99
|
|
|
{ |
100
|
|
|
$response = new Response(200, [], json_encode([ |
101
|
|
|
'result' => 'foo' |
102
|
|
|
])); |
103
|
|
|
|
104
|
|
|
$this->assertEquals('foo', $response->getRpcResult()); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testGetRpcResultIsNull() |
108
|
|
|
{ |
109
|
|
|
$response = new Response(200); |
110
|
|
|
|
111
|
|
|
$this->assertNull($response->getRpcResult()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
View Code Duplication |
public function testGetRpcVersion() |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
$response = new Response(200, [], json_encode([ |
117
|
|
|
'jsonrpc' => 'foo' |
118
|
|
|
])); |
119
|
|
|
|
120
|
|
|
$this->assertEquals('foo', $response->getRpcVersion()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testGetRpcVersionIsNull() |
124
|
|
|
{ |
125
|
|
|
$response = new Response(200); |
126
|
|
|
|
127
|
|
|
$this->assertNull($response->getRpcVersion()); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
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.