From e7dced3f6c4c9d7de6fd6f562e100c51ac79cbb3 Mon Sep 17 00:00:00 2001 From: Rodion Liuborets Date: Wed, 9 Jun 2021 18:50:41 +0300 Subject: [PATCH] SDK-1829-third-party-identity-check --- composer.json | 2 +- .../Check/SandboxThirdPartyIdentityCheck.php | 10 ++ .../SandboxThirdPartyIdentityCheckBuilder.php | 18 +++ src/DocScan/Request/SandboxCheckReports.php | 12 +- .../Request/SandboxCheckReportsBuilder.php | 19 +++- ...dboxThirdPartyIdentityCheckBuilderTest.php | 105 ++++++++++++++++++ .../Request/SandboxCheckReportsTest.php | 13 +++ 7 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 src/DocScan/Request/Check/SandboxThirdPartyIdentityCheck.php create mode 100644 src/DocScan/Request/Check/SandboxThirdPartyIdentityCheckBuilder.php create mode 100644 tests/DocScan/Request/Check/SandboxThirdPartyIdentityCheckBuilderTest.php diff --git a/composer.json b/composer.json index d44b937..38e884b 100755 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "yoti/yoti-php-sdk-sandbox", "description": "Yoti PHP SDK Sandbox", - "version": "1.5.0", + "version": "1.6.0", "keywords": [ "yoti", "sdk" diff --git a/src/DocScan/Request/Check/SandboxThirdPartyIdentityCheck.php b/src/DocScan/Request/Check/SandboxThirdPartyIdentityCheck.php new file mode 100644 index 0000000..c7aa43f --- /dev/null +++ b/src/DocScan/Request/Check/SandboxThirdPartyIdentityCheck.php @@ -0,0 +1,10 @@ +buildReport()); + return new SandboxThirdPartyIdentityCheck($result, $this->documentFilter); + } +} diff --git a/src/DocScan/Request/SandboxCheckReports.php b/src/DocScan/Request/SandboxCheckReports.php index 4a3c1b9..d7abede 100644 --- a/src/DocScan/Request/SandboxCheckReports.php +++ b/src/DocScan/Request/SandboxCheckReports.php @@ -10,6 +10,7 @@ use Yoti\Sandbox\DocScan\Request\Check\SandboxIdDocumentComparisonCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxLivenessCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxSupplementaryDocumentTextDataCheck; +use Yoti\Sandbox\DocScan\Request\Check\SandboxThirdPartyIdentityCheck; use Yoti\Util\Json; class SandboxCheckReports implements \JsonSerializable @@ -34,6 +35,11 @@ class SandboxCheckReports implements \JsonSerializable */ private $documentFaceMatchChecks; + /** + * @var SandboxThirdPartyIdentityCheck|null + */ + private $thirdPartyIdentityCheck; + /** * @var SandboxSupplementaryDocumentTextDataCheck[]|null */ @@ -59,6 +65,7 @@ class SandboxCheckReports implements \JsonSerializable * @param int|null $asyncReportDelay * @param SandboxIdDocumentComparisonCheck[]|null $idDocumentComparisonChecks * @param SandboxSupplementaryDocumentTextDataCheck[]|null $supplementaryDocumentTextDataChecks + * @param SandboxThirdPartyIdentityCheck|null $thirdPartyIdentityCheck */ public function __construct( array $documentTextDataChecks, @@ -67,7 +74,8 @@ public function __construct( array $livenessChecks, ?int $asyncReportDelay, ?array $idDocumentComparisonChecks = null, - ?array $supplementaryDocumentTextDataChecks = null + ?array $supplementaryDocumentTextDataChecks = null, + SandboxThirdPartyIdentityCheck $thirdPartyIdentityCheck = null ) { $this->documentTextDataChecks = $documentTextDataChecks; $this->documentAuthenticityChecks = $documentAuthenticityChecks; @@ -76,6 +84,7 @@ public function __construct( $this->asyncReportDelay = $asyncReportDelay; $this->idDocumentComparisonChecks = $idDocumentComparisonChecks; $this->supplementaryDocumentTextDataChecks = $supplementaryDocumentTextDataChecks; + $this->thirdPartyIdentityCheck = $thirdPartyIdentityCheck; } /** @@ -90,6 +99,7 @@ public function jsonSerialize(): \stdClass 'ID_DOCUMENT_COMPARISON' => $this->idDocumentComparisonChecks, 'SUPPLEMENTARY_DOCUMENT_TEXT_DATA_CHECK' => $this->supplementaryDocumentTextDataChecks, 'LIVENESS' => $this->livenessChecks, + 'THIRD_PARTY_IDENTITY' => $this->thirdPartyIdentityCheck, 'async_report_delay' => $this->asyncReportDelay, ]); } diff --git a/src/DocScan/Request/SandboxCheckReportsBuilder.php b/src/DocScan/Request/SandboxCheckReportsBuilder.php index a2625c8..3d87c2c 100644 --- a/src/DocScan/Request/SandboxCheckReportsBuilder.php +++ b/src/DocScan/Request/SandboxCheckReportsBuilder.php @@ -10,6 +10,7 @@ use Yoti\Sandbox\DocScan\Request\Check\SandboxIdDocumentComparisonCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxLivenessCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxSupplementaryDocumentTextDataCheck; +use Yoti\Sandbox\DocScan\Request\Check\SandboxThirdPartyIdentityCheck; class SandboxCheckReportsBuilder { @@ -43,6 +44,11 @@ class SandboxCheckReportsBuilder */ private $supplementaryDocumentTextDataChecks = []; + /** + * @var SandboxThirdPartyIdentityCheck + */ + private $thirdPartyIdentityCheck; + /** * @var int */ @@ -98,6 +104,16 @@ public function withIdDocumentComparisonCheck(SandboxIdDocumentComparisonCheck $ return $this; } + /** + * @param SandboxThirdPartyIdentityCheck $thirdPartyIdentityCheck + * @return $this + */ + public function withThirdPartyIdentityCheck(SandboxThirdPartyIdentityCheck $thirdPartyIdentityCheck): self + { + $this->thirdPartyIdentityCheck = $thirdPartyIdentityCheck; + return $this; + } + /** * @param int $asyncReportDelay * @return $this @@ -131,7 +147,8 @@ public function build(): SandboxCheckReports $this->livenessChecks, $this->asyncReportDelay, $this->idDocumentComparisonChecks, - $this->supplementaryDocumentTextDataChecks + $this->supplementaryDocumentTextDataChecks, + $this->thirdPartyIdentityCheck ); } } diff --git a/tests/DocScan/Request/Check/SandboxThirdPartyIdentityCheckBuilderTest.php b/tests/DocScan/Request/Check/SandboxThirdPartyIdentityCheckBuilderTest.php new file mode 100644 index 0000000..0a363b0 --- /dev/null +++ b/tests/DocScan/Request/Check/SandboxThirdPartyIdentityCheckBuilderTest.php @@ -0,0 +1,105 @@ +recommendationMock = $this->createMock(SandboxRecommendation::class); + $this->breakdownMock = $this->createMock(SandboxBreakdown::class); + } + + /** + * @test + */ + public function shouldThrowExceptionWhenMissingRecommendation(): void + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage(SandboxRecommendation::class); + + (new SandboxThirdPartyIdentityCheckBuilder())->build(); + } + + /** + * @test + */ + public function shouldBuildCorrectly(): void + { + $result = (new SandboxThirdPartyIdentityCheckBuilder()) + ->withRecommendation($this->recommendationMock) + ->withBreakdown($this->breakdownMock) + ->build(); + + $this->assertInstanceOf(SandboxThirdPartyIdentityCheck::class, $result); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'result' => [ + 'report' => [ + 'recommendation' => $this->recommendationMock, + 'breakdown' => [ + $this->breakdownMock + ], + ], + ], + ]), + json_encode($result) + ); + } + + /** + * @test + */ + public function shouldAllowOverwritingOfBreakdowns(): void + { + $breakdowns = [ + $this->breakdownMock, + $this->breakdownMock, + $this->breakdownMock + ]; + + $result = (new SandboxThirdPartyIdentityCheckBuilder()) + ->withRecommendation($this->recommendationMock) + ->withBreakdowns($breakdowns) + ->build(); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'result' => [ + 'report' => [ + 'recommendation' => $this->recommendationMock, + 'breakdown' => [ + $this->breakdownMock, + $this->breakdownMock, + $this->breakdownMock, + ], + ], + ], + ]), + json_encode($result) + ); + } +} diff --git a/tests/DocScan/Request/SandboxCheckReportsTest.php b/tests/DocScan/Request/SandboxCheckReportsTest.php index 8d29964..bf20a9d 100644 --- a/tests/DocScan/Request/SandboxCheckReportsTest.php +++ b/tests/DocScan/Request/SandboxCheckReportsTest.php @@ -10,6 +10,7 @@ use Yoti\Sandbox\DocScan\Request\Check\SandboxIdDocumentComparisonCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxLivenessCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxSupplementaryDocumentTextDataCheck; +use Yoti\Sandbox\DocScan\Request\Check\SandboxThirdPartyIdentityCheck; use Yoti\Sandbox\DocScan\Request\SandboxCheckReports; use Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder; use Yoti\Sandbox\Test\TestCase; @@ -46,6 +47,11 @@ class SandboxCheckReportsTest extends TestCase */ private $idDocumentComparisonCheckMock; + /** + * @var SandboxThirdPartyIdentityCheck + */ + private $thirdPartyIdentityCheckMock; + /** * @var SandboxSupplementaryDocumentTextDataCheck */ @@ -78,6 +84,11 @@ public function setup(): void ->method('jsonSerialize') ->willReturn((object) [ 'type' => 'documentComparisonCheck' ]); + $this->thirdPartyIdentityCheckMock = $this->createMock(SandboxThirdPartyIdentityCheck::class); + $this->thirdPartyIdentityCheckMock + ->method('jsonSerialize') + ->willReturn((object) [ 'type' => 'thirdPartyIdentityCheck' ]); + $this->supplementaryDocumentTextDataCheckMock = $this->createMock( SandboxSupplementaryDocumentTextDataCheck::class ); @@ -109,6 +120,7 @@ public function shouldBuildCorrectly() ->withDocumentFaceMatchCheck($this->documentFaceMatchCheckMock) ->withAsyncReportDelay(self::SOME_ASYNC_REPORT_DELAY) ->withSupplementaryDocumentTextDataCheck($this->supplementaryDocumentTextDataCheckMock) + ->withThirdPartyIdentityCheck($this->thirdPartyIdentityCheckMock) ->build(); $this->assertJsonStringEqualsJsonString( @@ -119,6 +131,7 @@ public function shouldBuildCorrectly() 'ID_DOCUMENT_FACE_MATCH' => [$this->documentFaceMatchCheckMock], 'LIVENESS' => [$this->livenessCheckMock], 'SUPPLEMENTARY_DOCUMENT_TEXT_DATA_CHECK' => [$this->supplementaryDocumentTextDataCheckMock], + 'THIRD_PARTY_IDENTITY' => $this->thirdPartyIdentityCheckMock, 'async_report_delay' => self::SOME_ASYNC_REPORT_DELAY ]), json_encode($result)