Skip to content

Commit 2df98bb

Browse files
committed
Add more tests
1 parent fed7287 commit 2df98bb

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/MessageTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ public function testParseRequestV2WithMethodStringAndParams(){
251251
Message::parseObject((object) ['jsonrpc'=>'2.0','method'=>'abc','params'=>null]);
252252
}
253253

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+
254265
/**
255266
* @return void
256267
* @throws JSONRPCException
@@ -345,6 +356,69 @@ public function testParseResponseV1WithResultNullAndErrorNumber(){
345356
Message::parseObject((object) ['result'=>null,'error'=>12.34]);
346357
}
347358

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+
348422
/**
349423
* @return void
350424
* @throws JSONRPCException

0 commit comments

Comments
 (0)