Skip to content

Commit

Permalink
Add getter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ben221199 committed May 17, 2024
1 parent ccac198 commit c660efe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,28 @@ public function hasId(bool $strictId=true): bool{
* @return bool
*/
public function hasMethod(): bool{
return property_exists($this->value,'method') && $this->value->method!=null;
return property_exists($this->value,'method') && $this->value->method!==null;
}

/**
* @return bool
*/
public function hasParams(): bool{
return property_exists($this->value,'params') && $this->value->params!=null;
return property_exists($this->value,'params') && $this->value->params!==null;
}

/**
* @return bool
*/
public function hasResult(): bool{
return property_exists($this->value,'result') && $this->value->result!=null;
return property_exists($this->value,'result') && $this->value->result!==null;
}

/**
* @return bool
*/
public function hasError(): bool{
return property_exists($this->value,'error') && $this->value->error!=null;
return property_exists($this->value,'error') && $this->value->error!==null;
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,28 @@ public function testParseUnknownVersion(){
]);
}

/**
* @return void
* @throws JSONRPCException
*/
public function testGetters(){
$this->assertEquals(123,Message::createRequestMessageV1(123,'myMethod')->getId());
$this->assertEquals('myMethod',Message::createRequestMessageV1(123,'myMethod')->getMethod());
$this->assertEquals([],Message::createRequestMessageV1(123,'myMethod')->getParams());

$this->assertNull(Message::createNotificationMessageV1('myMethod')->getId());
$this->assertEquals('myMethod',Message::createNotificationMessageV1('myMethod')->getMethod());
$this->assertEquals([],Message::createNotificationMessageV1('myMethod')->getParams());

$this->assertEquals(123,Message::createResponseMessageV1(123,'myResult')->getId());
$this->assertEquals('myResult',Message::createResponseMessageV1(123,'myResult')->getResult());
$this->assertNull(Message::createResponseMessageV1(123,'myResult')->getError());

$this->assertEquals(456,Message::createResponseMessageV1(123,null,(object) ['code'=>456,'message'=>'Some error text','data'=>true])->getErrorCode());
$this->assertEquals('Some error text',Message::createResponseMessageV1(123,null,(object) ['code'=>456,'message'=>'Some error text','data'=>true])->getErrorMessage());
$this->assertTrue(Message::createResponseMessageV1(123,null,(object) ['code'=>456,'message'=>'Some error text','data'=>true])->getErrorData());
}

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

0 comments on commit c660efe

Please sign in to comment.