diff --git a/composer.json b/composer.json index 6b58d9a..b26b1b7 100755 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "yoti/yoti-php-sdk-sandbox", "description": "Yoti PHP SDK Sandbox", - "version": "1.3.0", + "version": "1.4.0", "keywords": [ "yoti", "sdk" @@ -12,7 +12,7 @@ "yoti/yoti-php-sdk": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.2", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3", "squizlabs/php_codesniffer": "^3.4", "friendsofphp/php-cs-fixer": "^2.15", "brainmaestro/composer-git-hooks": "^2.8", diff --git a/sonar-project.properties b/sonar-project.properties index c87f6e5..80b2bab 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,7 +3,7 @@ sonar.organization = getyoti sonar.projectKey = getyoti:php-sandbox sonar.projectName = PHP SDK Sandbox -sonar.projectVersion = 1.3.0 +sonar.projectVersion = 1.4.0 sonar.language = php sonar.sources=src diff --git a/src/DocScan/Request/Check/SandboxDocumentTextDataCheckBuilder.php b/src/DocScan/Request/Check/SandboxDocumentTextDataCheckBuilder.php index e7d6f19..6cdce9d 100644 --- a/src/DocScan/Request/Check/SandboxDocumentTextDataCheckBuilder.php +++ b/src/DocScan/Request/Check/SandboxDocumentTextDataCheckBuilder.php @@ -8,9 +8,9 @@ class SandboxDocumentTextDataCheckBuilder extends SandboxDocumentCheckBuilder { /** - * @var array + * @var array|null */ - private $documentFields = []; + private $documentFields; /** * @param string $key diff --git a/src/DocScan/Request/Check/SandboxDocumentTextDataCheckResult.php b/src/DocScan/Request/Check/SandboxDocumentTextDataCheckResult.php index f2b36a3..f862adc 100644 --- a/src/DocScan/Request/Check/SandboxDocumentTextDataCheckResult.php +++ b/src/DocScan/Request/Check/SandboxDocumentTextDataCheckResult.php @@ -10,17 +10,17 @@ class SandboxDocumentTextDataCheckResult extends SandboxCheckResult { /** - * @var array + * @var array|null */ private $documentFields; /** * @param SandboxCheckReport $report - * @param array $documentFields + * @param array|null $documentFields */ public function __construct( SandboxCheckReport $report, - array $documentFields + ?array $documentFields ) { parent::__construct($report); $this->documentFields = $documentFields; @@ -32,7 +32,11 @@ public function __construct( public function jsonSerialize(): \stdClass { $jsonData = parent::jsonSerialize(); - $jsonData->document_fields = (object) $this->documentFields; + + if ($this->documentFields !== null) { + $jsonData->document_fields = (object) $this->documentFields; + } + return $jsonData; } } diff --git a/src/DocScan/Request/Check/SandboxIdDocumentComparisonCheck.php b/src/DocScan/Request/Check/SandboxIdDocumentComparisonCheck.php new file mode 100644 index 0000000..32137e3 --- /dev/null +++ b/src/DocScan/Request/Check/SandboxIdDocumentComparisonCheck.php @@ -0,0 +1,40 @@ +secondaryDocumentFilter = $secondaryDocumentFilter; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + $jsonData = parent::jsonSerialize(); + + if (isset($this->secondaryDocumentFilter)) { + $jsonData->secondary_document_filter = $this->secondaryDocumentFilter; + } + + return $jsonData; + } +} diff --git a/src/DocScan/Request/Check/SandboxIdDocumentComparisonCheckBuilder.php b/src/DocScan/Request/Check/SandboxIdDocumentComparisonCheckBuilder.php new file mode 100644 index 0000000..9d86fbf --- /dev/null +++ b/src/DocScan/Request/Check/SandboxIdDocumentComparisonCheckBuilder.php @@ -0,0 +1,35 @@ +secondaryDocumentFilter = $secondaryDocumentFilter; + return $this; + } + + /** + * @return SandboxIdDocumentComparisonCheck + */ + public function build(): SandboxCheck + { + $result = new SandboxCheckResult($this->buildReport()); + return new SandboxIdDocumentComparisonCheck($result, $this->secondaryDocumentFilter); + } +} diff --git a/src/DocScan/Request/SandboxCheckReports.php b/src/DocScan/Request/SandboxCheckReports.php index b4c6763..248ad85 100644 --- a/src/DocScan/Request/SandboxCheckReports.php +++ b/src/DocScan/Request/SandboxCheckReports.php @@ -4,10 +4,10 @@ namespace Yoti\Sandbox\DocScan\Request; -use Yoti\DocScan\Constants; use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentAuthenticityCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentFaceMatchCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentTextDataCheck; +use Yoti\Sandbox\DocScan\Request\Check\SandboxIdDocumentComparisonCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxLivenessCheck; use Yoti\Util\Json; @@ -24,6 +24,11 @@ class SandboxCheckReports implements \JsonSerializable */ private $documentAuthenticityChecks; + /** + * @var SandboxIdDocumentComparisonCheck[]|null + */ + private $idDocumentComparisonChecks; + /** * @var SandboxDocumentFaceMatchCheck[] */ @@ -47,19 +52,22 @@ class SandboxCheckReports implements \JsonSerializable * @param SandboxDocumentFaceMatchCheck[] $documentFaceMatchChecks * @param SandboxLivenessCheck[] $livenessChecks * @param int|null $asyncReportDelay + * @param SandboxIdDocumentComparisonCheck[]|null $idDocumentComparisonChecks */ public function __construct( array $documentTextDataChecks, array $documentAuthenticityChecks, array $documentFaceMatchChecks, array $livenessChecks, - ?int $asyncReportDelay + ?int $asyncReportDelay, + ?array $idDocumentComparisonChecks = null ) { $this->documentTextDataChecks = $documentTextDataChecks; $this->documentAuthenticityChecks = $documentAuthenticityChecks; $this->documentFaceMatchChecks = $documentFaceMatchChecks; $this->livenessChecks = $livenessChecks; $this->asyncReportDelay = $asyncReportDelay; + $this->idDocumentComparisonChecks = $idDocumentComparisonChecks; } /** @@ -68,10 +76,11 @@ public function __construct( public function jsonSerialize(): \stdClass { return (object) Json::withoutNullValues([ - Constants::ID_DOCUMENT_TEXT_DATA_CHECK => $this->documentTextDataChecks, - Constants::ID_DOCUMENT_AUTHENTICITY => $this->documentAuthenticityChecks, - Constants::ID_DOCUMENT_FACE_MATCH => $this->documentFaceMatchChecks, - Constants::LIVENESS => $this->livenessChecks, + 'ID_DOCUMENT_TEXT_DATA_CHECK' => $this->documentTextDataChecks, + 'ID_DOCUMENT_AUTHENTICITY' => $this->documentAuthenticityChecks, + 'ID_DOCUMENT_FACE_MATCH' => $this->documentFaceMatchChecks, + 'ID_DOCUMENT_COMPARISON' => $this->idDocumentComparisonChecks, + 'LIVENESS' => $this->livenessChecks, 'async_report_delay' => $this->asyncReportDelay, ]); } diff --git a/src/DocScan/Request/SandboxCheckReportsBuilder.php b/src/DocScan/Request/SandboxCheckReportsBuilder.php index 19b912a..58a5a4e 100644 --- a/src/DocScan/Request/SandboxCheckReportsBuilder.php +++ b/src/DocScan/Request/SandboxCheckReportsBuilder.php @@ -7,6 +7,7 @@ use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentAuthenticityCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentFaceMatchCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentTextDataCheck; +use Yoti\Sandbox\DocScan\Request\Check\SandboxIdDocumentComparisonCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxLivenessCheck; class SandboxCheckReportsBuilder @@ -22,6 +23,11 @@ class SandboxCheckReportsBuilder */ private $documentAuthenticityChecks = []; + /** + * @var SandboxIdDocumentComparisonCheck[] + */ + private $idDocumentComparisonChecks = []; + /** * @var SandboxDocumentFaceMatchCheck[] */ @@ -77,6 +83,16 @@ public function withDocumentFaceMatchCheck(SandboxDocumentFaceMatchCheck $docume return $this; } + /** + * @param SandboxIdDocumentComparisonCheck $documentComparisonCheck + * @return $this + */ + public function withIdDocumentComparisonCheck(SandboxIdDocumentComparisonCheck $documentComparisonCheck): self + { + $this->idDocumentComparisonChecks[] = $documentComparisonCheck; + return $this; + } + /** * @param int $asyncReportDelay * @return $this @@ -97,7 +113,8 @@ public function build(): SandboxCheckReports $this->documentAuthenticityChecks, $this->documentFaceMatchChecks, $this->livenessChecks, - $this->asyncReportDelay + $this->asyncReportDelay, + $this->idDocumentComparisonChecks ); } } diff --git a/src/DocScan/Request/Task/SandboxDocumentIdPhoto.php b/src/DocScan/Request/Task/SandboxDocumentIdPhoto.php new file mode 100644 index 0000000..3daff2e --- /dev/null +++ b/src/DocScan/Request/Task/SandboxDocumentIdPhoto.php @@ -0,0 +1,39 @@ +contentType = $contentType; + $this->data = $data; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'content_type' => $this->contentType, + 'data' => base64_encode($this->data), + ]; + } +} diff --git a/src/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskBuilder.php b/src/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskBuilder.php index 73a7051..6e64087 100644 --- a/src/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskBuilder.php +++ b/src/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskBuilder.php @@ -8,17 +8,21 @@ class SandboxDocumentTextDataExtractionTaskBuilder { - /** - * @var array + * @var array|null */ - private $documentFields = []; + private $documentFields; /** * @var SandboxDocumentFilter */ private $documentFilter; + /** + * @var SandboxDocumentIdPhoto + */ + private $documentIdPhoto; + /** * @param string $key * @param mixed $value @@ -51,12 +55,24 @@ public function withDocumentFilter(SandboxDocumentFilter $documentFilter): self return $this; } + /** + * @param string $contentType + * @param string $data + * + * @return $this + */ + public function withDocumentIdPhoto(string $contentType, string $data): self + { + $this->documentIdPhoto = new SandboxDocumentIdPhoto($contentType, $data); + return $this; + } + /** * @return SandboxDocumentTextDataExtractionTask */ public function build(): SandboxDocumentTextDataExtractionTask { - $result = new SandboxDocumentTextDataExtractionTaskResult($this->documentFields); + $result = new SandboxDocumentTextDataExtractionTaskResult($this->documentFields, $this->documentIdPhoto); return new SandboxDocumentTextDataExtractionTask($result, $this->documentFilter); } } diff --git a/src/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskResult.php b/src/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskResult.php index 664b132..17f84ec 100644 --- a/src/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskResult.php +++ b/src/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskResult.php @@ -6,19 +6,24 @@ class SandboxDocumentTextDataExtractionTaskResult implements \JsonSerializable { - /** - * @var array + * @var array|null */ private $documentFields; /** - * SandboxTaskResult constructor. - * @param array $documentFields + * @var SandboxDocumentIdPhoto|null + */ + private $documentIdPhoto; + + /** + * @param array|null $documentFields + * @param SandboxDocumentIdPhoto|null $documentIdPhoto */ - public function __construct(array $documentFields) + public function __construct(?array $documentFields, ?SandboxDocumentIdPhoto $documentIdPhoto = null) { $this->documentFields = $documentFields; + $this->documentIdPhoto = $documentIdPhoto; } /** @@ -26,8 +31,16 @@ public function __construct(array $documentFields) */ public function jsonSerialize(): \stdClass { - return (object) [ - 'document_fields' => (object) $this->documentFields, - ]; + $jsonData = (object) []; + + if ($this->documentFields !== null) { + $jsonData->document_fields = (object) $this->documentFields; + } + + if ($this->documentIdPhoto !== null) { + $jsonData->document_id_photo = $this->documentIdPhoto; + } + + return $jsonData; } } diff --git a/tests/DocScan/Request/Check/SandboxDocumentTextDataCheckBuilderTest.php b/tests/DocScan/Request/Check/SandboxDocumentTextDataCheckBuilderTest.php index 3e59d8a..fd0aa68 100644 --- a/tests/DocScan/Request/Check/SandboxDocumentTextDataCheckBuilderTest.php +++ b/tests/DocScan/Request/Check/SandboxDocumentTextDataCheckBuilderTest.php @@ -14,6 +14,12 @@ class SandboxDocumentTextDataCheckBuilderTest extends TestCase { + private const SOME_DOCUMENT_FIELD_KEY = 'someKey'; + private const SOME_DOCUMENT_FIELD_VALUE = 'someValue'; + private const SOME_OTHER_DOCUMENT_FIELD_KEY = 'someOtherKey'; + private const SOME_NESTED_DOCUMENT_FIELD_VALUE = [ + 'someNestedKey' => 'someNestedValue' + ]; /** * @var MockObject|SandboxRecommendation @@ -66,7 +72,6 @@ public function shouldBuildCorrectly(): void $this->breakdownMock ], ], - 'document_fields' => (object) [], ], ]), json_encode($result) @@ -81,8 +86,8 @@ public function shouldAllowAddingOfSingleDocumentFields(): void $result = (new SandboxDocumentTextDataCheckBuilder()) ->withRecommendation($this->recommendationMock) ->withBreakdown($this->breakdownMock) - ->withDocumentField('someKey', 'someValue') - ->withDocumentField('someOtherKey', 'someOtherValue') + ->withDocumentField(self::SOME_DOCUMENT_FIELD_KEY, self::SOME_DOCUMENT_FIELD_VALUE) + ->withDocumentField(self::SOME_OTHER_DOCUMENT_FIELD_KEY, self::SOME_NESTED_DOCUMENT_FIELD_VALUE) ->build(); $this->assertJsonStringEqualsJsonString( @@ -95,8 +100,8 @@ public function shouldAllowAddingOfSingleDocumentFields(): void ], ], 'document_fields' => [ - 'someKey' => 'someValue', - 'someOtherKey' => 'someOtherValue' + self::SOME_DOCUMENT_FIELD_KEY => self::SOME_DOCUMENT_FIELD_VALUE, + self::SOME_OTHER_DOCUMENT_FIELD_KEY => self::SOME_NESTED_DOCUMENT_FIELD_VALUE ], ], ]), @@ -110,8 +115,8 @@ public function shouldAllowAddingOfSingleDocumentFields(): void public function shouldAllowOverwritingOfAllDocumentFields(): void { $documentFields = [ - 'someKey' => 'someValue', - 'someOtherKey' => 'someOtherValue', + self::SOME_DOCUMENT_FIELD_KEY => self::SOME_DOCUMENT_FIELD_VALUE, + self::SOME_OTHER_DOCUMENT_FIELD_KEY => self::SOME_NESTED_DOCUMENT_FIELD_VALUE ]; $result = (new SandboxDocumentTextDataCheckBuilder()) @@ -149,11 +154,15 @@ public function shouldSerializeToJsonCorrectly() ->method('jsonSerialize') ->willReturn((object) [ 'someBreakdownKey' => 'someBreakdownValue' ]); + $documentFields = [ + self::SOME_DOCUMENT_FIELD_KEY => self::SOME_DOCUMENT_FIELD_VALUE, + self::SOME_OTHER_DOCUMENT_FIELD_KEY => self::SOME_NESTED_DOCUMENT_FIELD_VALUE + ]; + $result = (new SandboxDocumentTextDataCheckBuilder()) ->withRecommendation($this->recommendationMock) ->withBreakdown($this->breakdownMock) - ->withDocumentField('someKey', 'someValue') - ->withDocumentField('someOtherKey', 'someOtherValue') + ->withDocumentFields($documentFields) ->build(); $this->assertJsonStringEqualsJsonString( @@ -165,10 +174,7 @@ public function shouldSerializeToJsonCorrectly() $this->breakdownMock, ], ], - 'document_fields' => [ - 'someKey' => 'someValue', - 'someOtherKey' => 'someOtherValue' - ], + 'document_fields' => $documentFields, ], ]), json_encode($result) @@ -199,7 +205,6 @@ public function shouldBuildWithDocumentFilter(): void 'recommendation' => $this->recommendationMock, 'breakdown' => [], ], - 'document_fields' => (object) [], ], 'document_filter' => $documentFilter ]), diff --git a/tests/DocScan/Request/Check/SandboxIdDocumentComparisonCheckBuilderTest.php b/tests/DocScan/Request/Check/SandboxIdDocumentComparisonCheckBuilderTest.php new file mode 100644 index 0000000..fd0bdaa --- /dev/null +++ b/tests/DocScan/Request/Check/SandboxIdDocumentComparisonCheckBuilderTest.php @@ -0,0 +1,138 @@ +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 SandboxIdDocumentComparisonCheckBuilder())->build(); + } + + /** + * @test + */ + public function shouldBuildCorrectly(): void + { + $result = (new SandboxIdDocumentComparisonCheckBuilder()) + ->withRecommendation($this->recommendationMock) + ->withBreakdown($this->breakdownMock) + ->build(); + + $this->assertInstanceOf(SandboxIdDocumentComparisonCheck::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 SandboxIdDocumentComparisonCheckBuilder()) + ->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) + ); + } + + /** + * @test + */ + public function shouldBuildWithDocumentFilter(): void + { + $documentFilter = $this->createMock(SandboxDocumentFilter::class); + $documentFilter + ->method('jsonSerialize') + ->willReturn((object) ['some' => 'filter']); + + $result = (new SandboxIdDocumentComparisonCheckBuilder()) + ->withRecommendation($this->recommendationMock) + ->withSecondaryDocumentFilter($documentFilter) + ->build(); + + $this->assertInstanceOf(SandboxIdDocumentComparisonCheck::class, $result); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'result' => [ + 'report' => [ + 'recommendation' => $this->recommendationMock, + 'breakdown' => [], + ], + ], + 'secondary_document_filter' => $documentFilter + ]), + json_encode($result) + ); + } +} diff --git a/tests/DocScan/Request/SandboxCheckReportsTest.php b/tests/DocScan/Request/SandboxCheckReportsTest.php index 7f6bb3f..617872a 100644 --- a/tests/DocScan/Request/SandboxCheckReportsTest.php +++ b/tests/DocScan/Request/SandboxCheckReportsTest.php @@ -7,7 +7,9 @@ use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentAuthenticityCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentFaceMatchCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxDocumentTextDataCheck; +use Yoti\Sandbox\DocScan\Request\Check\SandboxIdDocumentComparisonCheck; use Yoti\Sandbox\DocScan\Request\Check\SandboxLivenessCheck; +use Yoti\Sandbox\DocScan\Request\SandboxCheckReports; use Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder; use Yoti\Sandbox\Test\TestCase; @@ -16,67 +18,121 @@ */ class SandboxCheckReportsTest extends TestCase { - private const SOME_ASYNC_REPORT_DELAY = 30; /** - * @test - * @covers ::__construct - * @covers ::jsonSerialize - * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withDocumentTextDataCheck - * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withDocumentAuthenticityCheck - * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withDocumentFaceMatchCheck - * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withLivenessCheck - * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withAsyncReportDelay - * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::build + * @var SandboxDocumentTextDataCheck */ - public function shouldBuildCorrectly() + private $documentTextDataCheckMock; + + /** + * @var SandboxDocumentAuthenticityCheck + */ + private $documentAuthenticityCheckMock; + + /** + * @var SandboxDocumentFaceMatchCheck + */ + private $documentFaceMatchCheckMock; + + /** + * @var SandboxLivenessCheck + */ + private $livenessCheckMock; + + /** + * @var SandboxIdDocumentComparisonCheck + */ + private $idDocumentComparisonCheckMock; + + public function setup(): void { - $documentTextDataCheckMock = $this->createMock(SandboxDocumentTextDataCheck::class); - $documentTextDataCheckMock + $this->documentTextDataCheckMock = $this->createMock(SandboxDocumentTextDataCheck::class); + $this->documentTextDataCheckMock ->method('jsonSerialize') ->willReturn((object) [ 'type' => 'documentTextDataCheck' ]); - $documentAuthenticityCheckMock = $this->createMock(SandboxDocumentAuthenticityCheck::class); - $documentAuthenticityCheckMock + $this->documentAuthenticityCheckMock = $this->createMock(SandboxDocumentAuthenticityCheck::class); + $this->documentAuthenticityCheckMock ->method('jsonSerialize') ->willReturn((object) [ 'type' => 'documentAuthenticityCheck' ]); - $documentFaceMatchCheckMock = $this->createMock(SandboxDocumentFaceMatchCheck::class); - $documentFaceMatchCheckMock + $this->documentFaceMatchCheckMock = $this->createMock(SandboxDocumentFaceMatchCheck::class); + $this->documentFaceMatchCheckMock ->method('jsonSerialize') ->willReturn((object) [ 'type' => 'documentFaceMatchCheck' ]); - $livenessCheckMock = $this->createMock(SandboxLivenessCheck::class); - $livenessCheckMock + $this->livenessCheckMock = $this->createMock(SandboxLivenessCheck::class); + $this->livenessCheckMock ->method('jsonSerialize') ->willReturn((object) [ 'type' => 'livenessCheck' ]); + $this->idDocumentComparisonCheckMock = $this->createMock(SandboxIdDocumentComparisonCheck::class); + $this->idDocumentComparisonCheckMock + ->method('jsonSerialize') + ->willReturn((object) [ 'type' => 'documentComparisonCheck' ]); + } + + /** + * @test + * @covers ::__construct + * @covers ::jsonSerialize + * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withDocumentTextDataCheck + * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withDocumentAuthenticityCheck + * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withIdDocumentComparisonCheck + * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withDocumentFaceMatchCheck + * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withLivenessCheck + * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::withAsyncReportDelay + * @covers \Yoti\Sandbox\DocScan\Request\SandboxCheckReportsBuilder::build + */ + public function shouldBuildCorrectly() + { $result = (new SandboxCheckReportsBuilder()) - ->withDocumentTextDataCheck($documentTextDataCheckMock) - ->withDocumentAuthenticityCheck($documentAuthenticityCheckMock) - ->withLivenessCheck($livenessCheckMock) - ->withDocumentFaceMatchCheck($documentFaceMatchCheckMock) + ->withDocumentTextDataCheck($this->documentTextDataCheckMock) + ->withDocumentAuthenticityCheck($this->documentAuthenticityCheckMock) + ->withIdDocumentComparisonCheck($this->idDocumentComparisonCheckMock) + ->withLivenessCheck($this->livenessCheckMock) + ->withDocumentFaceMatchCheck($this->documentFaceMatchCheckMock) ->withAsyncReportDelay(self::SOME_ASYNC_REPORT_DELAY) ->build(); $this->assertJsonStringEqualsJsonString( json_encode([ - 'ID_DOCUMENT_TEXT_DATA_CHECK' => [ - $documentTextDataCheckMock, - ], - 'ID_DOCUMENT_AUTHENTICITY' => [ - $documentAuthenticityCheckMock, - ], - 'ID_DOCUMENT_FACE_MATCH' => [ - $documentFaceMatchCheckMock, - ], - 'LIVENESS' => [ - $livenessCheckMock, - ], + 'ID_DOCUMENT_TEXT_DATA_CHECK' => [$this->documentTextDataCheckMock], + 'ID_DOCUMENT_AUTHENTICITY' => [$this->documentAuthenticityCheckMock], + 'ID_DOCUMENT_COMPARISON' => [$this->idDocumentComparisonCheckMock], + 'ID_DOCUMENT_FACE_MATCH' => [$this->documentFaceMatchCheckMock], + 'LIVENESS' => [$this->livenessCheckMock], 'async_report_delay' => self::SOME_ASYNC_REPORT_DELAY ]), json_encode($result) ); } + + /** + * @test + * @covers ::__construct + * @covers ::jsonSerialize + */ + public function shouldConstructWithoutOptionalArguments() + { + $checkReports = new SandboxCheckReports( + [$this->documentTextDataCheckMock], + [$this->documentAuthenticityCheckMock], + [$this->documentFaceMatchCheckMock], + [$this->livenessCheckMock], + self::SOME_ASYNC_REPORT_DELAY + ); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'ID_DOCUMENT_TEXT_DATA_CHECK' => [$this->documentTextDataCheckMock], + 'ID_DOCUMENT_AUTHENTICITY' => [$this->documentAuthenticityCheckMock], + 'ID_DOCUMENT_FACE_MATCH' => [$this->documentFaceMatchCheckMock], + 'LIVENESS' => [$this->livenessCheckMock], + 'async_report_delay' => self::SOME_ASYNC_REPORT_DELAY, + ]), + json_encode($checkReports) + ); + } } diff --git a/tests/DocScan/Request/Task/SandboxDocumentIdPhotoTest.php b/tests/DocScan/Request/Task/SandboxDocumentIdPhotoTest.php new file mode 100644 index 0000000..116b5f8 --- /dev/null +++ b/tests/DocScan/Request/Task/SandboxDocumentIdPhotoTest.php @@ -0,0 +1,38 @@ +assertJsonStringEqualsJsonString( + json_encode([ + 'content_type' => self::SOME_IMAGE_CONTENT_TYPE, + 'data' => base64_encode(self::SOME_IMAGE_CONTENT), + ]), + json_encode($documentIdPhoto) + ); + } +} diff --git a/tests/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskBuilderTest.php b/tests/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskBuilderTest.php index 65b395e..b92472c 100644 --- a/tests/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskBuilderTest.php +++ b/tests/DocScan/Request/Task/SandboxDocumentTextDataExtractionTaskBuilderTest.php @@ -2,9 +2,10 @@ declare(strict_types=1); -namespace Yoti\Sandbox\Test\DocScan\Task; +namespace Yoti\Sandbox\Test\DocScan\Request\Task; use Yoti\Sandbox\DocScan\Request\SandboxDocumentFilter; +use Yoti\Sandbox\DocScan\Request\Task\SandboxDocumentIdPhoto; use Yoti\Sandbox\DocScan\Request\Task\SandboxDocumentTextDataExtractionTaskBuilder; use Yoti\Sandbox\Test\TestCase; @@ -13,9 +14,14 @@ */ class SandboxDocumentTextDataExtractionTaskBuilderTest extends TestCase { - private const SOME_DOCUMENT_FIELD_KEY = 'someKey'; private const SOME_DOCUMENT_FIELD_VALUE = 'someValue'; + private const SOME_OTHER_DOCUMENT_FIELD_KEY = 'someOtherKey'; + private const SOME_NESTED_DOCUMENT_FIELD_VALUE = [ + 'someNestedKey' => 'someNestedValue' + ]; + private const SOME_IMAGE_CONTENT_TYPE = 'image/jpeg'; + private const SOME_IMAGE_CONTENT = 'someImageContent'; /** * @test @@ -30,6 +36,7 @@ public function shouldAllowIndividualDocumentFields(): void { $result = (new SandboxDocumentTextDataExtractionTaskBuilder()) ->withDocumentField(self::SOME_DOCUMENT_FIELD_KEY, self::SOME_DOCUMENT_FIELD_VALUE) + ->withDocumentField(self::SOME_OTHER_DOCUMENT_FIELD_KEY, self::SOME_NESTED_DOCUMENT_FIELD_VALUE) ->build(); $this->assertJsonStringEqualsJsonString( @@ -37,6 +44,7 @@ public function shouldAllowIndividualDocumentFields(): void 'result' => [ 'document_fields' => [ self::SOME_DOCUMENT_FIELD_KEY => self::SOME_DOCUMENT_FIELD_VALUE, + self::SOME_OTHER_DOCUMENT_FIELD_KEY => self::SOME_NESTED_DOCUMENT_FIELD_VALUE, ], ], ]), @@ -57,6 +65,7 @@ public function shouldAllowOverridingOfDocumentFields(): void { $documentFields = [ self::SOME_DOCUMENT_FIELD_KEY => self::SOME_DOCUMENT_FIELD_VALUE, + self::SOME_OTHER_DOCUMENT_FIELD_KEY => self::SOME_NESTED_DOCUMENT_FIELD_VALUE ]; $result = (new SandboxDocumentTextDataExtractionTaskBuilder()) @@ -66,9 +75,7 @@ public function shouldAllowOverridingOfDocumentFields(): void $this->assertJsonStringEqualsJsonString( json_encode([ 'result' => [ - 'document_fields' => [ - self::SOME_DOCUMENT_FIELD_KEY => self::SOME_DOCUMENT_FIELD_VALUE, - ], + 'document_fields' => $documentFields, ], ]), json_encode($result) @@ -95,12 +102,38 @@ public function shouldHaveDocumentFilter(): void ->withDocumentFilter($documentFilter) ->build(); + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'result' => (object) [], + 'document_filter' => $documentFilter, + ]), + json_encode($result) + ); + } + + /** + * @test + * @covers ::withDocumentIdPhoto + * @covers ::build + * @covers \Yoti\Sandbox\DocScan\Request\Task\SandboxDocumentTextDataExtractionTask::__construct + * @covers \Yoti\Sandbox\DocScan\Request\Task\SandboxDocumentTextDataExtractionTask::jsonSerialize + * @covers \Yoti\Sandbox\DocScan\Request\Task\SandboxDocumentTextDataExtractionTaskResult::__construct + * @covers \Yoti\Sandbox\DocScan\Request\Task\SandboxDocumentTextDataExtractionTaskResult::jsonSerialize + */ + public function shouldHaveDocumentIdPhoto(): void + { + $result = (new SandboxDocumentTextDataExtractionTaskBuilder()) + ->withDocumentIdPhoto(self::SOME_IMAGE_CONTENT_TYPE, self::SOME_IMAGE_CONTENT) + ->build(); + $this->assertJsonStringEqualsJsonString( json_encode([ 'result' => [ - 'document_fields' => (object) [], + 'document_id_photo' => new SandboxDocumentIdPhoto( + self::SOME_IMAGE_CONTENT_TYPE, + self::SOME_IMAGE_CONTENT + ), ], - 'document_filter' => $documentFilter, ]), json_encode($result) );