Skip to content

Commit c660efe

Browse files
committed
Add getter tests
1 parent ccac198 commit c660efe

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/Message.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,28 @@ public function hasId(bool $strictId=true): bool{
8383
* @return bool
8484
*/
8585
public function hasMethod(): bool{
86-
return property_exists($this->value,'method') && $this->value->method!=null;
86+
return property_exists($this->value,'method') && $this->value->method!==null;
8787
}
8888

8989
/**
9090
* @return bool
9191
*/
9292
public function hasParams(): bool{
93-
return property_exists($this->value,'params') && $this->value->params!=null;
93+
return property_exists($this->value,'params') && $this->value->params!==null;
9494
}
9595

9696
/**
9797
* @return bool
9898
*/
9999
public function hasResult(): bool{
100-
return property_exists($this->value,'result') && $this->value->result!=null;
100+
return property_exists($this->value,'result') && $this->value->result!==null;
101101
}
102102

103103
/**
104104
* @return bool
105105
*/
106106
public function hasError(): bool{
107-
return property_exists($this->value,'error') && $this->value->error!=null;
107+
return property_exists($this->value,'error') && $this->value->error!==null;
108108
}
109109

110110
/**

tests/MessageTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,28 @@ public function testParseUnknownVersion(){
342342
]);
343343
}
344344

345+
/**
346+
* @return void
347+
* @throws JSONRPCException
348+
*/
349+
public function testGetters(){
350+
$this->assertEquals(123,Message::createRequestMessageV1(123,'myMethod')->getId());
351+
$this->assertEquals('myMethod',Message::createRequestMessageV1(123,'myMethod')->getMethod());
352+
$this->assertEquals([],Message::createRequestMessageV1(123,'myMethod')->getParams());
353+
354+
$this->assertNull(Message::createNotificationMessageV1('myMethod')->getId());
355+
$this->assertEquals('myMethod',Message::createNotificationMessageV1('myMethod')->getMethod());
356+
$this->assertEquals([],Message::createNotificationMessageV1('myMethod')->getParams());
357+
358+
$this->assertEquals(123,Message::createResponseMessageV1(123,'myResult')->getId());
359+
$this->assertEquals('myResult',Message::createResponseMessageV1(123,'myResult')->getResult());
360+
$this->assertNull(Message::createResponseMessageV1(123,'myResult')->getError());
361+
362+
$this->assertEquals(456,Message::createResponseMessageV1(123,null,(object) ['code'=>456,'message'=>'Some error text','data'=>true])->getErrorCode());
363+
$this->assertEquals('Some error text',Message::createResponseMessageV1(123,null,(object) ['code'=>456,'message'=>'Some error text','data'=>true])->getErrorMessage());
364+
$this->assertTrue(Message::createResponseMessageV1(123,null,(object) ['code'=>456,'message'=>'Some error text','data'=>true])->getErrorData());
365+
}
366+
345367
/**
346368
* @return void
347369
* @throws JSONRPCException

0 commit comments

Comments
 (0)