Skip to content

Commit

Permalink
SDK-2265 added test FetchShareReceipt and updated ReceiptItemKeyTest,…
Browse files Browse the repository at this point in the history
… code quality updates
  • Loading branch information
mehmet-yoti committed Jun 19, 2024
1 parent a6d34f6 commit b8b963a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
ignoreErrors:
- '#Variable property access on (.*)#'
4 changes: 2 additions & 2 deletions src/DigitalIdentityClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class DigitalIdentityClient
{
private DigitalIdentityService $digitalIdentityService;
public string $id='';
public string $id = '';
/**
* DigitalIdentityClient constructor.
*
Expand Down Expand Up @@ -112,7 +112,7 @@ public function fetchShareReceipt(string $receiptId): Identity\Receipt
return $this->digitalIdentityService->fetchShareReceipt($receiptId);
}

public function getSdkID()
public function getSdkID(): string
{
return $this->id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Profile/Util/Attribute/AnchorConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private static function convertCertToX509(string $certificate): \stdClass
});

//$decodedX509Data = Json::decode(Json::encode($X509Data), false);
$decodedX509Data = Json::decode(Json::encode(Json::convert_from_latin1_to_utf8_recursively($X509Data)), false);
$decodedX509Data = Json::decode(Json::encode(Json::convertFromLatin1ToUtf8Recursively($X509Data)), false);
// Ensure serial number is cast to string.
// @see \phpseclib\Math\BigInteger::__toString()
$decodedX509Data
Expand Down
12 changes: 7 additions & 5 deletions src/Util/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,20 @@ private static function validate(): void
}
}

public static function convert_from_latin1_to_utf8_recursively($dat)
public static function convertFromLatin1ToUtf8Recursively(mixed $dat): mixed
{
if (is_string($dat)) {
return utf8_encode($dat);
} elseif (is_array($dat)) {
$ret = [];
foreach ($dat as $i => $d) $ret[ $i ] = self::convert_from_latin1_to_utf8_recursively($d);

foreach ($dat as $i => $d) {
$ret[$i] = self::convertFromLatin1ToUtf8Recursively($d);
}
return $ret;
} elseif (is_object($dat)) {
foreach ($dat as $i => $d) $dat->$i = self::convert_from_latin1_to_utf8_recursively($d);

foreach (get_object_vars($dat) as $i => $d) {
$dat->$i = self::convertFromLatin1ToUtf8Recursively($d);
}
return $dat;
} else {
return $dat;
Expand Down
18 changes: 18 additions & 0 deletions tests/Identity/DigitalIdentityServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Yoti\Identity\DigitalIdentityService;
use Yoti\Identity\Extension\Extension;
use Yoti\Identity\Policy\Policy;
use Yoti\Identity\Receipt;
use Yoti\Identity\ShareSessionCreated;
use Yoti\Identity\ShareSessionCreatedQrCode;
use Yoti\Identity\ShareSessionFetched;
Expand Down Expand Up @@ -130,4 +131,21 @@ public function testShouldFetchShareSession()

$this->assertInstanceOf(ShareSessionFetched::class, $result);
}

/**
* @covers ::fetchShareReceipt
* @covers ::__construct
*/
public function testShouldFetchShareReceipt()
{
$response = $this->createMock(ResponseInterface::class);

$response->method('getStatusCode')->willReturn(201);

$identityService = $this->createMock(DigitalIdentityService::class);

$result = $identityService->fetchShareReceipt(TestData::SOME_ID);

$this->assertInstanceOf(Receipt::class, $result);
}
}
14 changes: 5 additions & 9 deletions tests/Identity/ReceiptItemKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace Yoti\Test\Identity;

use Yoti\Exception\EncryptedDataException;
use Yoti\Identity\ReceiptItemKey;
use Yoti\Test\TestCase;
use Yoti\Test\TestData;

/**
* @coversDefaultClass \Yoti\Identity\ReceiptItemKey
Expand All @@ -19,23 +17,21 @@ class ReceiptItemKeyTest extends TestCase
* @covers ::setIv
* @covers ::__construct
*/
/*public function testShouldBuildCorrectly()
public function testShouldBuildCorrectly()
{
$someId = 'SOME_ID';
$someIv = TestData::YOTI_CONNECT_TOKEN_DECRYPTED;
$someValue = 'weofmwrfmwrkfmwepkfmwprekmf';
$someIv = 'd2VvZm13cmZtd3JrZm13ZXBrZm13cHJla21m';
$someValue = 'ZDJWdlptMTNjbVp0ZDNKclptMTNaWEJyWm0xM2NISmxhMjFt';

$sessionData = [
'id' => $someId,
'iv' => $someIv,
'value' => base64_encode($someValue)
'value' => $someValue
];

$this->expectException(EncryptedDataException::class);
$receiptItemKey = new ReceiptItemKey($sessionData);

$this->assertEquals($someId, $receiptItemKey->getId());
$this->assertEquals($someValue, $receiptItemKey->getValue());
}*/
}
}

0 comments on commit b8b963a

Please sign in to comment.