@@ -251,6 +251,17 @@ public function testParseRequestV2WithMethodStringAndParams(){
251
251
Message::parseObject ((object ) ['jsonrpc ' =>'2.0 ' ,'method ' =>'abc ' ,'params ' =>null ]);
252
252
}
253
253
254
+ /**
255
+ * @return void
256
+ * @throws JSONRPCException
257
+ */
258
+ public function testParseRequestV2WithMethodStringAndParamsFalse (){
259
+ $ this ->expectException (JSONRPCException::class);
260
+ $ this ->expectExceptionMessage ('[V2] The "params" property MUST be an string, number or null if present. ' );
261
+
262
+ Message::parseObject ((object ) ['jsonrpc ' =>'2.0 ' ,'id ' =>false ,'method ' =>'abc ' ,'params ' =>[]]);
263
+ }
264
+
254
265
/**
255
266
* @return void
256
267
* @throws JSONRPCException
@@ -345,6 +356,69 @@ public function testParseResponseV1WithResultNullAndErrorNumber(){
345
356
Message::parseObject ((object ) ['result ' =>null ,'error ' =>12.34 ]);
346
357
}
347
358
359
+ /**
360
+ * @return void
361
+ * @throws JSONRPCException
362
+ */
363
+ public function testParseResponseV2WithResultNullAndErrorObject (){
364
+ $ this ->expectException (JSONRPCException::class);
365
+ $ this ->expectExceptionMessage ('[V2] The error object MUST have a "code" property. ' );
366
+
367
+ Message::parseObject ((object ) ['jsonrpc ' =>'2.0 ' ,'error ' =>(object ) []]);
368
+ }
369
+
370
+ /**
371
+ * @return void
372
+ * @throws JSONRPCException
373
+ */
374
+ public function testParseResponseV2WithResultNullAndErrorObjectCode (){
375
+ $ this ->expectException (JSONRPCException::class);
376
+ $ this ->expectExceptionMessage ('[V2] The error object MUST have a "message" property. ' );
377
+
378
+ Message::parseObject ((object ) ['jsonrpc ' =>'2.0 ' ,'error ' =>(object ) ['code ' =>null ]]);
379
+ }
380
+
381
+ /**
382
+ * @return void
383
+ * @throws JSONRPCException
384
+ */
385
+ public function testParseResponseV2WithResultNullAndErrorObjectCodeNumber (){
386
+ $ this ->expectException (JSONRPCException::class);
387
+ $ this ->expectExceptionMessage ('[V2] The error object MUST have a "message" property. ' );
388
+
389
+ Message::parseObject ((object ) ['jsonrpc ' =>'2.0 ' ,'error ' =>(object ) ['code ' =>123 ]]);
390
+ }
391
+
392
+ /**
393
+ * @return void
394
+ * @throws JSONRPCException
395
+ */
396
+ public function testParseResponseV2WithResultNullAndErrorObjectCodeNumberAndMessage (){
397
+ $ this ->expectException (JSONRPCException::class);
398
+ $ this ->expectExceptionMessage ('[V2] The "message" property of the error object MUST be a string. ' );
399
+
400
+ Message::parseObject ((object ) ['jsonrpc ' =>'2.0 ' ,'error ' =>(object ) ['code ' =>123 ,'message ' =>null ]]);
401
+ }
402
+
403
+ /**
404
+ * @return void
405
+ * @throws JSONRPCException
406
+ */
407
+ public function testParseResponseV2WithResultNullAndErrorObjectCodeNumberAndMessageString (){
408
+ $ this ->expectException (JSONRPCException::class);
409
+ $ this ->expectExceptionMessage ('[V2] Missing "id" property in response. ' );
410
+
411
+ Message::parseObject ((object ) ['jsonrpc ' =>'2.0 ' ,'error ' =>(object ) ['code ' =>123 ,'message ' =>'Some error ' ]]);
412
+ }
413
+
414
+ /**
415
+ * @return void
416
+ * @throws JSONRPCException
417
+ */
418
+ public function testParseResponseV2WithResultNullAndErrorObjectCodeNumberAndMessageStringAndId (){
419
+ $ this ->assertInstanceOf (ResponseMessage::class,Message::parseObject ((object ) ['jsonrpc ' =>'2.0 ' ,'id ' =>123 ,'error ' =>(object ) ['code ' =>456 ,'message ' =>'Some error ' ]]));
420
+ }
421
+
348
422
/**
349
423
* @return void
350
424
* @throws JSONRPCException
0 commit comments