Skip to content

Commit

Permalink
SDK-2438 added face comparison and added related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet-yoti committed Aug 20, 2024
1 parent 5c8627c commit c444d1f
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/DocScan/Request/Check/SandboxFaceComparisonCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Yoti\Sandbox\DocScan\Request\Check;

use Yoti\Sandbox\DocScan\SandboxConstants;

class SandboxFaceComparisonCheck extends SandboxCheck
{
/**
* @var SandboxFaceComparisonCheckConfig
*/
private $config;

public function __construct(SandboxFaceComparisonCheckConfig $config)
{
$this->config = $config;
}

protected function getType(): string
{
return SandboxConstants::FACE_COMPARISON;
}

protected function getConfig(): ?SandboxCheckConfigInterface
{
return $this->config;
}
}
19 changes: 19 additions & 0 deletions src/DocScan/Request/Check/SandboxFaceComparisonCheckBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Yoti\Sandbox\DocScan\Request\Check;

use Yoti\Sandbox\DocScan\Request\Traits\Builder\SandboxManualCheckTrait;
use Yoti\Util\Validation;

class SandboxFaceComparisonCheckBuilder
{
use SandboxManualCheckTrait;

public function build(): SandboxFaceComparisonCheck
{
Validation::notEmptyString($this->manualCheck, 'manualCheck');

$config = new SandboxFaceComparisonCheckConfig($this->manualCheck);
return new SandboxFaceComparisonCheck($config);
}
}
36 changes: 36 additions & 0 deletions src/DocScan/Request/Check/SandboxFaceComparisonCheckConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Yoti\Sandbox\DocScan\Request\Check;

use stdClass;

class SandboxFaceComparisonCheckConfig implements SandboxCheckConfigInterface
{
/**
* @var string
*/
private $manualCheck;

public function __construct(string $manualCheck)
{
$this->manualCheck = $manualCheck;
}

/**
* @return stdClass
*/
public function jsonSerialize(): stdClass
{
return (object) [
'manual_check' => $this->getManualCheck(),
];
}

/**
* @return string
*/
public function getManualCheck(): string
{
return $this->manualCheck;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Yoti\Sandbox\Test\DocScan\Request\Check;

use Yoti\Sandbox\DocScan\Request\Check\SandboxFaceComparisonCheck;
use Yoti\Sandbox\DocScan\Request\Check\SandboxFaceComparisonCheckBuilder;
use Yoti\Sandbox\Test\TestCase;

/**
* @coversDefaultClass \Yoti\Sandbox\DocScan\Request\Check\SandboxFaceComparisonCheckBuilder
*/
class SandboxFaceComparisonCheckBuilderTest extends TestCase
{
/**
* @test
* @covers ::withManualCheckAlways
* @covers ::setManualCheck
* @covers ::build
*/
public function shouldCorrectlyBuildSandboxFaceMatchCheck()
{
$result = (new SandboxFaceComparisonCheckBuilder())
->withManualCheckNever()
->build();

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

/**
* @test
* @covers \Yoti\Sandbox\DocScan\Request\Check\SandboxFaceComparisonCheck::jsonSerialize
* @covers ::withManualCheckNever
* @covers ::setManualCheck
* @covers ::build
* @covers \Yoti\Sandbox\DocScan\Request\Check\SandboxFaceComparisonCheck::__construct
* @covers \Yoti\Sandbox\DocScan\Request\Check\SandboxFaceComparisonCheck::getConfig
* @covers \Yoti\Sandbox\DocScan\Request\Check\SandboxFaceComparisonCheck::getType
*/
public function shouldReturnTheCorrectValuesWhenManualCheckIsNever()
{
$result = (new SandboxFaceComparisonCheckBuilder())
->withManualCheckNever()
->build();

$expected = [
'type' => 'FACE_COMPARISON',
'config' => [
'manual_check' => 'NEVER',
],
];

$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($result));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Yoti\Sandbox\Test\DocScan\Request\Check;

use Yoti\Sandbox\DocScan\Request\Check\SandboxFaceComparisonCheckConfig;
use Yoti\Sandbox\Test\TestCase;

/**
* @coversDefaultClass \Yoti\Sandbox\DocScan\Request\Check\SandboxFaceComparisonCheckConfig
*/
class SandboxFaceComparisonCheckConfigTest extends TestCase
{
private const SOME_MANUAL_CHECK = 'someManualCheck';

/**
* @test
* @covers ::__construct
* @covers ::getManualCheck
*/
public function shouldHoldValuesCorrectly()
{
$result = new SandboxFaceComparisonCheckConfig(self::SOME_MANUAL_CHECK);

$this->assertEquals(self::SOME_MANUAL_CHECK, $result->getManualCheck());
}

/**
* @test
* @covers ::jsonSerialize
*/
public function shouldSerializeToJsonCorrectly()
{
$result = new SandboxFaceComparisonCheckConfig(self::SOME_MANUAL_CHECK);

$expected = [
'manual_check' => self::SOME_MANUAL_CHECK,
];

$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($result));
}
}

0 comments on commit c444d1f

Please sign in to comment.