@@ -42,6 +42,30 @@ public function testDecodeJSONArray(){
42
42
$ this ->assertEquals ([],Message::decodeJSON ('[] ' ));
43
43
}
44
44
45
+ /**
46
+ * @return void
47
+ * @throws JSONRPCException
48
+ */
49
+ public function testEncodeJSONString (){
50
+ $ this ->assertEquals ('"abc" ' ,Message::encodeJSON ('abc ' ));
51
+ }
52
+
53
+ /**
54
+ * @return void
55
+ * @throws JSONRPCException
56
+ */
57
+ public function testEncodeJSONObject (){
58
+ $ this ->assertEquals ('{} ' ,Message::encodeJSON ((object ) []));
59
+ }
60
+
61
+ /**
62
+ * @return void
63
+ * @throws JSONRPCException
64
+ */
65
+ public function testEncodeJSONArray (){
66
+ $ this ->assertEquals ('[] ' ,Message::encodeJSON ([]));
67
+ }
68
+
45
69
public function testIsBatch (){
46
70
$ this ->assertTrue (Message::isBatch ([]));
47
71
@@ -234,6 +258,17 @@ public function testParseResponseV1WithResultAndError(){
234
258
Message::parseObject ((object ) ['result ' =>'abc ' ,'error ' =>'def ' ]);
235
259
}
236
260
261
+ /**
262
+ * @return void
263
+ * @throws JSONRPCException
264
+ */
265
+ public function testParseResponseV1WithResultNullAndErrorNumber (){
266
+ $ this ->expectException (JSONRPCException::class);
267
+ $ this ->expectExceptionMessage ('[V1] The "error" property in request MUST be an string, object or null. ' );
268
+
269
+ Message::parseObject ((object ) ['result ' =>null ,'error ' =>12.34 ]);
270
+ }
271
+
237
272
/**
238
273
* @return void
239
274
* @throws JSONRPCException
@@ -300,13 +335,65 @@ public function testParseUnknownVersion(){
300
335
* @return void
301
336
* @throws JSONRPCException
302
337
*/
303
- public function testMessages (){
304
- $ this ->assertEquals ((object ) ["id " =>123 ,"method " =>"myMethod " ,"params " =>[]],Message::createRequestMessageV1 (123 ,'myMethod ' )->toObject ());
305
- $ this ->assertEquals ((object ) ["id " =>123 ,"method " =>"myMethod " ,"params " =>["a " ,1 ,false ,12.34 ]],Message::createRequestMessageV1 (123 ,'myMethod ' ,['a ' ,1 ,false ,12.34 ])->toObject ());
306
- $ this ->assertEquals ((object ) ["id " =>null ,"method " =>"myMethod " ,"params " =>[]],Message::createNotificationMessageV1 ('myMethod ' )->toObject ());
307
- $ this ->assertEquals ((object ) ["id " =>null ,"method " =>"myMethod " ,"params " =>["b " ,0 ,true ,34.12 ]],Message::createNotificationMessageV1 ('myMethod ' ,['b ' ,0 ,true ,34.12 ])->toObject ());
308
- $ this ->assertEquals ((object ) ["id " =>123 ,"result " =>"myResult " ,"error " =>null ],Message::createResponseMessageV1 (123 ,'myResult ' )->toObject ());
309
- $ this ->assertEquals ((object ) ["id " =>123 ,"result " =>null ,"error " =>"myError " ],Message::createResponseMessageV1 (123 ,null ,'myError ' )->toObject ());
338
+ public function testIsRequest (){
339
+ $ this ->assertTrue (Message::createRequestMessageV1 (123 ,'myMethod ' )->isRequest ());
340
+ $ this ->assertTrue (Message::createNotificationMessageV1 ('myMethod ' )->isRequest ());
341
+ $ this ->assertFalse (Message::createResponseMessageV1 (123 ,'myResult ' )->isRequest ());
342
+ }
343
+
344
+ /**
345
+ * @return void
346
+ * @throws JSONRPCException
347
+ */
348
+ public function testIsNotification (){
349
+ $ this ->assertFalse (Message::createRequestMessageV1 (123 ,'myMethod ' )->isNotification ());
350
+ $ this ->assertTrue (Message::createNotificationMessageV1 ('myMethod ' )->isNotification ());
351
+ $ this ->assertFalse (Message::createResponseMessageV1 (123 ,'myResult ' )->isNotification ());
352
+ }
353
+
354
+ /**
355
+ * @return void
356
+ * @throws JSONRPCException
357
+ */
358
+ public function testIsResponse (){
359
+ $ this ->assertFalse (Message::createRequestMessageV1 (123 ,'myMethod ' )->isResponse ());
360
+ $ this ->assertFalse (Message::createNotificationMessageV1 ('myMethod ' )->isResponse ());
361
+ $ this ->assertTrue (Message::createResponseMessageV1 (123 ,'myResult ' )->isResponse ());
362
+ }
363
+
364
+ /**
365
+ * @return void
366
+ * @throws JSONRPCException
367
+ */
368
+ public function testCreateResponseMessageV1WithResultAndError (){
369
+ $ this ->expectException (JSONRPCException::class);
370
+ $ this ->expectExceptionMessage ('[V1] Only one property "result" or "error" can be non null. ' );
371
+
372
+ Message::createResponseMessageV1 (123 ,'abc ' ,'def ' );
373
+ }
374
+
375
+ /**
376
+ * @return void
377
+ * @throws JSONRPCException
378
+ */
379
+ public function testCreateResponseMessageV1WithErrorFalse (){
380
+ $ this ->expectException (JSONRPCException::class);
381
+ $ this ->expectExceptionMessage ('[V1] The "error" property in request MUST be an string, object or null. ' );
382
+
383
+ Message::createResponseMessageV1 (123 ,null ,false );
310
384
}
311
385
386
+ // /**
387
+ // * @return void
388
+ // * @throws JSONRPCException
389
+ // */
390
+ // public function testMessages(){
391
+ // $this->assertEquals((object) ["id"=>123,"method"=>"myMethod","params"=>[]],Message::createRequestMessageV1(123,'myMethod')->toObject());
392
+ // $this->assertEquals((object) ["id"=>123,"method"=>"myMethod","params"=>["a",1,false,12.34]],Message::createRequestMessageV1(123,'myMethod',['a',1,false,12.34])->toObject());
393
+ // $this->assertEquals((object) ["id"=>null,"method"=>"myMethod","params"=>[]],Message::createNotificationMessageV1('myMethod')->toObject());
394
+ // $this->assertEquals((object) ["id"=>null,"method"=>"myMethod","params"=>["b",0,true,34.12]],Message::createNotificationMessageV1('myMethod',['b',0,true,34.12])->toObject());
395
+ // $this->assertEquals((object) ["id"=>123,"result"=>"myResult","error"=>null],Message::createResponseMessageV1(123,'myResult')->toObject());
396
+ // $this->assertEquals((object) ["id"=>123,"result"=>null,"error"=>"myError"],Message::createResponseMessageV1(123,null,'myError')->toObject());
397
+ // }
398
+
312
399
}
0 commit comments