5
5
6
6
use YOCLIB \JSONRPC \JSONRPCException ;
7
7
use YOCLIB \JSONRPC \Message ;
8
+ use YOCLIB \JSONRPC \NotificationMessage ;
9
+ use YOCLIB \JSONRPC \RequestMessage ;
8
10
use YOCLIB \JSONRPC \ResponseMessage ;
9
11
10
12
class MessageTest extends TestCase{
@@ -140,6 +142,17 @@ public function testParseRequestV1WithMethod(){
140
142
Message::parseObject ((object ) ['method ' =>null ]);
141
143
}
142
144
145
+ /**
146
+ * @return void
147
+ * @throws JSONRPCException
148
+ */
149
+ public function testParseRequestV1WithMethodString (){
150
+ $ this ->expectException (JSONRPCException::class);
151
+ $ this ->expectExceptionMessage ('[V1] Missing "params" property in request. ' );
152
+
153
+ Message::parseObject ((object ) ['method ' =>'abc ' ]);
154
+ }
155
+
143
156
/**
144
157
* @return void
145
158
* @throws JSONRPCException
@@ -151,6 +164,43 @@ public function testParseRequestV1WithParams(){
151
164
Message::parseObject ((object ) ['params ' =>null ]);
152
165
}
153
166
167
+ /**
168
+ * @return void
169
+ * @throws JSONRPCException
170
+ */
171
+ public function testParseRequestV1WithMethodStringAndParams (){
172
+ $ this ->expectException (JSONRPCException::class);
173
+ $ this ->expectExceptionMessage ('[V1] The "params" property in request MUST be an array. ' );
174
+
175
+ Message::parseObject ((object ) ['method ' =>'abc ' ,'params ' =>null ]);
176
+ }
177
+
178
+
179
+ /**
180
+ * @return void
181
+ * @throws JSONRPCException
182
+ */
183
+ public function testParseRequestV1WithMethodStringAndParamsArray (){
184
+ $ this ->assertInstanceOf (NotificationMessage::class,Message::parseObject ((object ) ['method ' =>'abc ' ,'params ' =>[]]));
185
+ }
186
+
187
+ /**
188
+ * @return void
189
+ * @throws JSONRPCException
190
+ */
191
+ public function testParseRequestV1WithIdNullAndMethodStringAndParamsArray (){
192
+ $ this ->assertInstanceOf (NotificationMessage::class,Message::parseObject ((object ) ['id ' =>null ,'method ' =>'abc ' ,'params ' =>[]]));
193
+ }
194
+
195
+ /**
196
+ * @return void
197
+ * @throws JSONRPCException
198
+ */
199
+ public function testParseRequestV1WithIdFalsyAndMethodStringAndParamsArray (){
200
+ $ this ->assertInstanceOf (RequestMessage::class,Message::parseObject ((object ) ['id ' =>false ,'method ' =>'abc ' ,'params ' =>[]]));
201
+ $ this ->assertInstanceOf (NotificationMessage::class,Message::parseObject ((object ) ['id ' =>false ,'method ' =>'abc ' ,'params ' =>[]],false ));
202
+ }
203
+
154
204
/**
155
205
* @return void
156
206
* @throws JSONRPCException
@@ -217,6 +267,7 @@ public function testParseResponseV1WithIdNullAndResultAndNullError(){
217
267
*/
218
268
public function testParseResponseV1WithIdFalsyAndResultAndNullError (){
219
269
$ this ->assertInstanceOf (ResponseMessage::class,Message::parseObject ((object ) ['id ' =>false ,'result ' =>'abc ' ,'error ' =>null ]));
270
+ $ this ->assertInstanceOf (ResponseMessage::class,Message::parseObject ((object ) ['id ' =>false ,'result ' =>'abc ' ,'error ' =>null ],false ));
220
271
}
221
272
222
273
/**
0 commit comments