Skip to content

Commit

Permalink
Merge pull request #23 from mrevib/feature/SP-247
Browse files Browse the repository at this point in the history
Feature/sp 247
  • Loading branch information
bobbrodie authored Oct 14, 2022
2 parents 239141d + 1a1d0ba commit 870a945
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/BitPayKeyUtils/KeyHelper/PublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public function __toString()
*/
public function isValid()
{
return ((!empty($this->hex) && ctype_xdigit($this->hex)) && (!empty($this->dec) && ctype_digit($this->dec)));
return ((!empty($this->hex) && ctype_xdigit((string)$this->hex)) &&
(!empty($this->dec) && ctype_digit((string)$this->dec)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/BitPayKeyUtils/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static function guid()
*/
public static function encodeHex($dec)
{
if (!is_string($dec) && !ctype_digit($dec)) {
if (!is_string($dec) && !ctype_digit((string)$dec)) {
throw new Exception(sprintf('Argument is expected to be a string of decimal numbers.
You passed in "%s"', gettype($dec)));
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BitPayKeyUtils/KeyHelper/PublicKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function testIsValidWhenIsValid()
public function testIsValidWhenIsInvalid()
{
$testedObject = $this->getTestedClassObject();
$this->setProtectedPropertyValue($testedObject, 'dec', 10);
$this->setProtectedPropertyValue($testedObject, 'dec', null);
$this->setProtectedPropertyValue($testedObject, 'hex', 'FF5733');
$result = $testedObject->isValid();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/BitPayKeyUtils/Storage/test1.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
O:17:"Mock_Key_78449d0f":0:{}
O:17:"Mock_Key_7dd5a46d":0:{}
2 changes: 1 addition & 1 deletion test/unit/BitPayKeyUtils/Storage/test11.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b4fdbf3d113c186f12fcf501ebbef8d2ed6087743804e954d78f3ddca35c25b2
c31eda5dd0eb0a1f93800db68d1ae0fd60daae108ae31cc034711b4a0e7bcebe
25 changes: 9 additions & 16 deletions test/unit/BitPayKeyUtils/Util/UtilTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use BitPayKeyUtils\Util\PointInterface;
use BitPayKeyUtils\Util\Point;
use BitPayKeyUtils\Util\Util;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -77,7 +77,7 @@ public function testEncodeHexException()
$this->expectException(Exception::class);

$util = $this->createClassObject();
$util::encodeHex(123);
$util::encodeHex(null);
}

public function testEncodeHex1()
Expand All @@ -96,13 +96,6 @@ public function testEncodeHex2()
$this->assertEquals($expectedValue, $util::encodeHex('450'));
}

public function testDoubleAndAdd()
{
$pointInterface = $this->getMockBuilder(PointInterface::class)->getMock();
$util = $this->createClassObject();
$this->assertIsObject($util::doubleAndAdd('123', $pointInterface));
}

public function testDecToBin()
{
$expectedValue = '0011111';
Expand All @@ -121,7 +114,7 @@ public function testDecodeHex()

public function testPointDouble()
{
$pointInterface = $this->getMockBuilder(PointInterface::class)->getMock();
$pointInterface = $this->getMockBuilder(Point::class)->disableOriginalConstructor()->getMock();
$pointInterface->method('getX')->willReturn('5');
$pointInterface->method('getY')->willReturn('3');

Expand All @@ -134,11 +127,11 @@ public function testPointDouble()

public function testPointAdd()
{
$pointInterfaceP = $this->getMockBuilder(PointInterface::class)->getMock();
$pointInterfaceP = $this->getMockBuilder(Point::class)->disableOriginalConstructor()->getMock();
$pointInterfaceP->method('getX')->willReturn('6');
$pointInterfaceP->method('getY')->willReturn('9');

$pointInterfaceQ = $this->getMockBuilder(PointInterface::class)->getMock();
$pointInterfaceQ = $this->getMockBuilder(Point::class)->disableOriginalConstructor()->getMock();
$pointInterfaceQ->method('getX')->willReturn('8');
$pointInterfaceQ->method('getY')->willReturn('2');

Expand All @@ -151,11 +144,11 @@ public function testPointAdd()

public function testPointAddSameValues()
{
$pointInterfaceP = $this->getMockBuilder(PointInterface::class)->getMock();
$pointInterfaceP = $this->getMockBuilder(Point::class)->disableOriginalConstructor()->getMock();
$pointInterfaceP->method('getX')->willReturn('5');
$pointInterfaceP->method('getY')->willReturn('3');

$pointInterfaceQ = $this->getMockBuilder(PointInterface::class)->getMock();
$pointInterfaceQ = $this->getMockBuilder(Point::class)->disableOriginalConstructor()->getMock();
$pointInterfaceQ->method('getX')->willReturn('5');
$pointInterfaceQ->method('getY')->willReturn('3');

Expand All @@ -168,12 +161,12 @@ public function testPointAddSameValues()

public function testPointAddInfinity()
{
$pointInterfaceP = $this->getMockBuilder(PointInterface::class)->getMock();
$pointInterfaceP = $this->getMockBuilder(Point::class)->disableOriginalConstructor()->getMock();
$pointInterfaceP->method('isInfinity')->willReturn(false);
$pointInterfaceP->method('getX')->willReturn('1');
$pointInterfaceP->method('getY')->willReturn('2');

$pointInterfaceQ = $this->getMockBuilder(PointInterface::class)->getMock();
$pointInterfaceQ = $this->getMockBuilder(Point::class)->disableOriginalConstructor()->getMock();
$pointInterfaceQ->method('isInfinity')->willReturn(true);

$util = $this->createClassObject();
Expand Down

0 comments on commit 870a945

Please sign in to comment.