Skip to content

Commit 26eecd8

Browse files
committed
Rename function
1 parent b550622 commit 26eecd8

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/Message.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private static function handleMessage(object $message,bool $strictId=true){
153153
*/
154154
private static function handleMessageV2(object $message,bool $strictId=true){
155155
if(self::isRequestMessage($message)){
156-
self::validateMethodPropertyV1($message);
156+
self::validateMethodProperty($message);
157157
return null;
158158
}elseif(self::isResponseMessage($message)){
159159
return null;
@@ -184,12 +184,12 @@ private static function isResponseMessage(object $message): bool{
184184
* @return void
185185
* @throws JSONRPCException
186186
*/
187-
private static function validateMethodPropertyV1(object $message){
187+
private static function validateMethodProperty(object $message){
188188
if(!property_exists($message,'method')){
189-
throw new JSONRPCException('[V1] Missing "method" property in request.');
189+
throw new JSONRPCException('Missing "method" property in request.');
190190
}
191191
if(!is_string($message->method)){
192-
throw new JSONRPCException('[V1] The "method" property in request MUST be a string.');
192+
throw new JSONRPCException('The "method" property in request MUST be a string.');
193193
}
194194
}
195195

@@ -240,7 +240,7 @@ private static function validateErrorPropertyV1(object $message){
240240
*/
241241
private static function handleMessageV1(object $message,bool $strictId=true){
242242
if(self::isRequestMessage($message)){
243-
self::validateMethodPropertyV1($message);
243+
self::validateMethodProperty($message);
244244
self::validateParamsPropertyV1($message);
245245

246246
if(property_exists($message,'id') && ($strictId?($message->id!==null):($message->id))){

tests/MessageTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ public function testEncodeJSONArray(){
6666
$this->assertEquals('[]',Message::encodeJSON([]));
6767
}
6868

69+
/**
70+
* @return void
71+
* @throws JSONRPCException
72+
*/
73+
public function testEncodeJSONResource(){
74+
$this->expectException(JSONRPCException::class);
75+
$this->expectExceptionMessage('Failed to encode JSON.');
76+
77+
Message::encodeJSON(tmpfile());
78+
}
79+
6980
public function testIsBatch(){
7081
$this->assertTrue(Message::isBatch([]));
7182

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

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

188199
Message::parseObject((object) ['params'=>null]);
189200
}
@@ -383,6 +394,10 @@ public function testCreateResponseMessageV1WithErrorFalse(){
383394
Message::createResponseMessageV1(123,null,false);
384395
}
385396

397+
public function testToObject(){
398+
$this->assertEquals((object) ['id'=>123,'method'=>'getMethod','params'=>['param1','param2']],Message::createRequestMessageV1(123,'getMethod',['param1','param2'])->toObject());
399+
}
400+
386401
// /**
387402
// * @return void
388403
// * @throws JSONRPCException

0 commit comments

Comments
 (0)