Skip to content

Commit

Permalink
Rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
ben221199 committed May 17, 2024
1 parent b550622 commit 26eecd8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static function handleMessage(object $message,bool $strictId=true){
*/
private static function handleMessageV2(object $message,bool $strictId=true){
if(self::isRequestMessage($message)){
self::validateMethodPropertyV1($message);
self::validateMethodProperty($message);
return null;
}elseif(self::isResponseMessage($message)){
return null;
Expand Down Expand Up @@ -184,12 +184,12 @@ private static function isResponseMessage(object $message): bool{
* @return void
* @throws JSONRPCException
*/
private static function validateMethodPropertyV1(object $message){
private static function validateMethodProperty(object $message){
if(!property_exists($message,'method')){
throw new JSONRPCException('[V1] Missing "method" property in request.');
throw new JSONRPCException('Missing "method" property in request.');
}
if(!is_string($message->method)){
throw new JSONRPCException('[V1] The "method" property in request MUST be a string.');
throw new JSONRPCException('The "method" property in request MUST be a string.');
}
}

Expand Down Expand Up @@ -240,7 +240,7 @@ private static function validateErrorPropertyV1(object $message){
*/
private static function handleMessageV1(object $message,bool $strictId=true){
if(self::isRequestMessage($message)){
self::validateMethodPropertyV1($message);
self::validateMethodProperty($message);
self::validateParamsPropertyV1($message);

if(property_exists($message,'id') && ($strictId?($message->id!==null):($message->id))){
Expand Down
19 changes: 17 additions & 2 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ public function testEncodeJSONArray(){
$this->assertEquals('[]',Message::encodeJSON([]));
}

/**
* @return void
* @throws JSONRPCException
*/
public function testEncodeJSONResource(){
$this->expectException(JSONRPCException::class);
$this->expectExceptionMessage('Failed to encode JSON.');

Message::encodeJSON(tmpfile());
}

public function testIsBatch(){
$this->assertTrue(Message::isBatch([]));

Expand Down Expand Up @@ -161,7 +172,7 @@ public function testParseEmptyObject(){
*/
public function testParseRequestV1WithMethod(){
$this->expectException(JSONRPCException::class);
$this->expectExceptionMessage('[V1] The "method" property in request MUST be a string.');
$this->expectExceptionMessage('The "method" property in request MUST be a string.');

Message::parseObject((object) ['method'=>null]);
}
Expand All @@ -183,7 +194,7 @@ public function testParseRequestV1WithMethodString(){
*/
public function testParseRequestV1WithParams(){
$this->expectException(JSONRPCException::class);
$this->expectExceptionMessage('[V1] Missing "method" property in request.');
$this->expectExceptionMessage('Missing "method" property in request.');

Message::parseObject((object) ['params'=>null]);
}
Expand Down Expand Up @@ -383,6 +394,10 @@ public function testCreateResponseMessageV1WithErrorFalse(){
Message::createResponseMessageV1(123,null,false);
}

public function testToObject(){
$this->assertEquals((object) ['id'=>123,'method'=>'getMethod','params'=>['param1','param2']],Message::createRequestMessageV1(123,'getMethod',['param1','param2'])->toObject());
}

// /**
// * @return void
// * @throws JSONRPCException
Expand Down

0 comments on commit 26eecd8

Please sign in to comment.