Skip to content

Commit 7dd8a43

Browse files
authored
SDK-2159 Face Comparison Check (#302)
1 parent a3ff3c5 commit 7dd8a43

File tree

6 files changed

+179
-0
lines changed

6 files changed

+179
-0
lines changed

src/DocScan/Constants.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Constants
1414
public const LIVENESS = 'LIVENESS';
1515
public const WATCHLIST_SCREENING = 'WATCHLIST_SCREENING';
1616
public const WATCHLIST_ADVANCED_CA = 'WATCHLIST_ADVANCED_CA';
17+
public const FACE_COMPARISON = 'FACE_COMPARISON';
1718

1819
public const WITH_YOTI_ACCOUNT = 'WITH_YOTI_ACCOUNT';
1920
public const WITH_CUSTOM_ACCOUNT = 'WITH_CUSTOM_ACCOUNT';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Create\Check;
4+
5+
use Yoti\DocScan\Constants;
6+
7+
class RequestedFaceComparisonCheck extends RequestedCheck
8+
{
9+
/**
10+
* @var RequestedFaceComparisonCheckConfig
11+
*/
12+
private $config;
13+
14+
public function __construct(RequestedFaceComparisonCheckConfig $config)
15+
{
16+
$this->config = $config;
17+
}
18+
19+
protected function getType(): string
20+
{
21+
return Constants::FACE_COMPARISON;
22+
}
23+
24+
protected function getConfig(): ?RequestedCheckConfigInterface
25+
{
26+
return $this->config;
27+
}
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Create\Check;
4+
5+
use Yoti\DocScan\Session\Create\Traits\Builder\ManualCheckTrait;
6+
use Yoti\Util\Validation;
7+
8+
class RequestedFaceComparisonCheckBuilder
9+
{
10+
use ManualCheckTrait;
11+
12+
public function build(): RequestedFaceComparisonCheck
13+
{
14+
Validation::notEmptyString($this->manualCheck, 'manualCheck');
15+
16+
$config = new RequestedFaceComparisonCheckConfig($this->manualCheck);
17+
return new RequestedFaceComparisonCheck($config);
18+
}
19+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Create\Check;
4+
5+
use stdClass;
6+
7+
class RequestedFaceComparisonCheckConfig implements RequestedCheckConfigInterface
8+
{
9+
/**
10+
* @var string
11+
*/
12+
private $manualCheck;
13+
14+
public function __construct(string $manualCheck)
15+
{
16+
$this->manualCheck = $manualCheck;
17+
}
18+
19+
/**
20+
* @return stdClass
21+
*/
22+
public function jsonSerialize(): stdClass
23+
{
24+
return (object) [
25+
'manual_check' => $this->getManualCheck(),
26+
];
27+
}
28+
29+
/**
30+
* @return string
31+
*/
32+
public function getManualCheck(): string
33+
{
34+
return $this->manualCheck;
35+
}
36+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Yoti\Test\DocScan\Session\Create\Check;
4+
5+
use Yoti\DocScan\Session\Create\Check\RequestedFaceComparisonCheck;
6+
use Yoti\DocScan\Session\Create\Check\RequestedFaceComparisonCheckBuilder;
7+
use Yoti\Test\TestCase;
8+
9+
/**
10+
* @coversDefaultClass \Yoti\DocScan\Session\Create\Check\RequestedFaceComparisonCheckBuilder
11+
*/
12+
class RequestedFaceComparisonCheckBuilderTest extends TestCase
13+
{
14+
/**
15+
* @test
16+
* @covers ::withManualCheckAlways
17+
* @covers ::setManualCheck
18+
* @covers ::build
19+
*/
20+
public function shouldCorrectlyBuildRequestedFaceMatchCheck()
21+
{
22+
$result = (new RequestedFaceComparisonCheckBuilder())
23+
->withManualCheckNever()
24+
->build();
25+
26+
$this->assertInstanceOf(RequestedFaceComparisonCheck::class, $result);
27+
}
28+
29+
/**
30+
* @test
31+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedFaceComparisonCheck::jsonSerialize
32+
* @covers ::withManualCheckNever
33+
* @covers ::setManualCheck
34+
* @covers ::build
35+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedFaceComparisonCheck::__construct
36+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedFaceComparisonCheck::getConfig
37+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedFaceComparisonCheck::getType
38+
*/
39+
public function shouldReturnTheCorrectValuesWhenManualCheckIsNever()
40+
{
41+
$result = (new RequestedFaceComparisonCheckBuilder())
42+
->withManualCheckNever()
43+
->build();
44+
45+
$expected = [
46+
'type' => 'FACE_COMPARISON',
47+
'config' => [
48+
'manual_check' => 'NEVER',
49+
],
50+
];
51+
52+
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($result));
53+
}
54+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Yoti\Test\DocScan\Session\Create\Check;
4+
5+
use Yoti\DocScan\Session\Create\Check\RequestedFaceComparisonCheckConfig;
6+
use Yoti\Test\TestCase;
7+
8+
/**
9+
* @coversDefaultClass \Yoti\DocScan\Session\Create\Check\RequestedFaceComparisonCheckConfig
10+
*/
11+
class RequestedFaceComparisonCheckConfigTest extends TestCase
12+
{
13+
private const SOME_MANUAL_CHECK = 'someManualCheck';
14+
15+
/**
16+
* @test
17+
* @covers ::__construct
18+
* @covers ::getManualCheck
19+
*/
20+
public function shouldHoldValuesCorrectly()
21+
{
22+
$result = new RequestedFaceComparisonCheckConfig(self::SOME_MANUAL_CHECK);
23+
24+
$this->assertEquals(self::SOME_MANUAL_CHECK, $result->getManualCheck());
25+
}
26+
27+
/**
28+
* @test
29+
* @covers ::jsonSerialize
30+
*/
31+
public function shouldSerializeToJsonCorrectly()
32+
{
33+
$result = new RequestedFaceComparisonCheckConfig(self::SOME_MANUAL_CHECK);
34+
35+
$expected = [
36+
'manual_check' => self::SOME_MANUAL_CHECK,
37+
];
38+
39+
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($result));
40+
}
41+
}

0 commit comments

Comments
 (0)