Skip to content

Commit

Permalink
SDK-2438 added static liveness and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet-yoti committed Mar 22, 2024
1 parent 296ed39 commit 77213a7
Show file tree
Hide file tree
Showing 32 changed files with 129 additions and 35 deletions.
8 changes: 5 additions & 3 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('Protobuf')
->exclude('vendor')
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->in(__DIR__ . '/examples')
;

return PhpCsFixer\Config::create()
$config = new PhpCsFixer\Config();
$config
->setRiskyAllowed(true)
->setRules([
'array_syntax' => ['syntax' => 'short'],
'no_unused_imports' => true,
Expand All @@ -24,3 +24,5 @@
])
->setFinder($finder)
;

return $config;
19 changes: 14 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "yoti/yoti-php-sdk-sandbox",
"description": "Yoti PHP SDK Sandbox",
"version": "1.6.0",
"version": "1.7.0",
"keywords": [
"yoti",
"sdk"
],
"homepage": "https://yoti.com",
"license": "MIT",
"require": {
"php": "^7.1 || ^8.0",
"yoti/yoti-php-sdk": "^3.1"
"php": "^7.1 || ^8.0 || ^8.1",
"yoti/yoti-php-sdk": "^4.2"
},
"require-dev": {
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.3",
"squizlabs/php_codesniffer": "^3.4",
"friendsofphp/php-cs-fixer": "^2.15",
"friendsofphp/php-cs-fixer": "^3.4",
"brainmaestro/composer-git-hooks": "^2.8",
"phpstan/phpstan-strict-rules": "^0.12.1",
"phpstan/extension-installer": "^1.0",
Expand All @@ -36,9 +36,13 @@
"test": "phpunit",
"coverage-clover": "phpunit --coverage-clover ./coverage/coverage.xml",
"coverage-html": "phpunit --coverage-html ./coverage/report",
"fix": [
"php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=no",
"phpcbf"
],
"lint": [
"phpcs",
"php-cs-fixer fix --config=.php_cs.dist -v --dry-run --using-cache=no --diff-format=udiff --ansi",
"php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --using-cache=no",
"phpstan analyse"
],
"post-install-cmd": "cghooks add --ignore-lock",
Expand All @@ -48,5 +52,10 @@
"hooks": {
"pre-commit": "composer test && composer lint"
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
1 change: 0 additions & 1 deletion src/DocScan/Request/Check/Report/SandboxBreakdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class SandboxBreakdown implements \JsonSerializable
{

/**
* @var string
*/
Expand Down
1 change: 0 additions & 1 deletion src/DocScan/Request/Check/Report/SandboxCheckReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class SandboxCheckReport implements \JsonSerializable
{

/**
* @var SandboxRecommendation
*/
Expand Down
1 change: 0 additions & 1 deletion src/DocScan/Request/Check/Report/SandboxDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class SandboxDetail implements \JsonSerializable
{

/**
* @var string
*/
Expand Down
1 change: 0 additions & 1 deletion src/DocScan/Request/Check/Report/SandboxRecommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class SandboxRecommendation implements \JsonSerializable
{

/**
* @var string|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class SandboxRecommendationBuilder
{

/**
* @var string
*/
Expand Down
1 change: 0 additions & 1 deletion src/DocScan/Request/Check/SandboxCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class SandboxCheck implements \JsonSerializable
{

/**
* @var SandboxCheckResult
*/
Expand Down
1 change: 0 additions & 1 deletion src/DocScan/Request/Check/SandboxCheckBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

abstract class SandboxCheckBuilder
{

/**
* @var SandboxRecommendation
*/
Expand Down
1 change: 0 additions & 1 deletion src/DocScan/Request/Check/SandboxCheckResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class SandboxCheckResult implements \JsonSerializable
{

/**
* @var SandboxCheckReport
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class SandboxDocumentAuthenticityCheck extends SandboxDocumentCheck
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class SandboxDocumentAuthenticityCheckBuilder extends SandboxDocumentCheckBuilder
{

/**
* @return SandboxDocumentAuthenticityCheck
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class SandboxDocumentFaceMatchCheck extends SandboxDocumentCheck
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class SandboxDocumentFaceMatchCheckBuilder extends SandboxDocumentCheckBuilder
{

/**
* @return SandboxDocumentFaceMatchCheck
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class SandboxDocumentTextDataCheckBuilder extends SandboxDocumentCheckBuilder
{

/**
* @var array<string, mixed>|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class SandboxDocumentTextDataCheckResult extends SandboxCheckResult
{

/**
* @var array<string, mixed>|null
*/
Expand Down
18 changes: 18 additions & 0 deletions src/DocScan/Request/Check/SandboxStaticLivenessCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Yoti\Sandbox\DocScan\Request\Check;

class SandboxStaticLivenessCheck extends SandboxLivenessCheck
{
private const STATIC = 'STATIC';

/**
* @param SandboxCheckResult $result
*/
public function __construct(SandboxCheckResult $result)
{
parent::__construct($result, self::STATIC);
}
}
17 changes: 17 additions & 0 deletions src/DocScan/Request/Check/SandboxStaticLivenessCheckBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Yoti\Sandbox\DocScan\Request\Check;

class SandboxStaticLivenessCheckBuilder extends SandboxCheckBuilder
{
/**
* @return SandboxStaticLivenessCheck
*/
public function build(): SandboxCheck
{
$result = new SandboxCheckResult($this->buildReport());
return new SandboxStaticLivenessCheck($result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class SandboxSupplementaryDocumentTextDataCheckResult extends SandboxCheckResult
{

/**
* @var array<string, mixed>|null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class SandboxThirdPartyIdentityCheck extends SandboxDocumentCheck
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class SandboxThirdPartyIdentityCheckBuilder extends SandboxDocumentCheckBuilder
{

/**
* @return SandboxThirdPartyIdentityCheck
*/
Expand Down
1 change: 0 additions & 1 deletion src/DocScan/Request/SandboxResponseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class SandboxResponseConfig implements \JsonSerializable
{

/**
* @var SandboxTaskResults|null
*/
Expand Down
1 change: 0 additions & 1 deletion src/DocScan/Request/SandboxResponseConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class SandboxResponseConfigBuilder
{

/**
* @var SandboxTaskResults
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class SandboxBreakdownTest extends TestCase
{

private const SOME_SUB_CHECK = 'someSubCheck';
private const SOME_RESULT = 'someResult';

Expand Down
1 change: 0 additions & 1 deletion tests/DocScan/Request/Check/Report/SandboxDetailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class SandboxDetailTest extends TestCase
{

private const SOME_NAME = 'someName';
private const SOME_VALUE = 'someValue';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class SandboxRecommendationTest extends TestCase
{

private const SOME_VALUE = 'someValue';
private const SOME_REASON = 'someReason';
private const SOME_RECOVERY_SUGGESTION = 'someRecoverySuggestion';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class SandboxDocumentAuthenticityCheckBuilderTest extends TestCase
{

/**
* @var MockObject|SandboxRecommendation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class SandboxDocumentFaceMatchCheckBuilderTest extends TestCase
{

/**
* @var MockObject|SandboxRecommendation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class SandboxIdDocumentComparisonCheckBuilderTest extends TestCase
{

/**
* @var MockObject|SandboxRecommendation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

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

use PHPUnit\Framework\MockObject\MockObject;
use Yoti\Sandbox\DocScan\Request\Check\Report\SandboxBreakdown;
use Yoti\Sandbox\DocScan\Request\Check\Report\SandboxRecommendation;
use Yoti\Sandbox\DocScan\Request\Check\SandboxLivenessCheck;
use Yoti\Sandbox\DocScan\Request\Check\SandboxStaticLivenessCheck;
use Yoti\Sandbox\DocScan\Request\Check\SandboxStaticLivenessCheckBuilder;
use Yoti\Sandbox\Test\TestCase;

class SandboxStaticLivenessCheckBuilderTest extends TestCase
{
/**
* @var MockObject|SandboxRecommendation
*/
private $recommendationMock;

/**
* @var MockObject|SandboxBreakdown
*/
private $breakdownMock;

/**
* @before
*/
public function setUp(): void
{
$this->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 SandboxStaticLivenessCheckBuilder())->build();
}

/**
* @test
*/
public function shouldBuildCorrectly(): void
{
$result = (new SandboxStaticLivenessCheckBuilder())
->withRecommendation($this->recommendationMock)
->withBreakdown($this->breakdownMock)
->build();

$this->assertInstanceOf(SandboxStaticLivenessCheck::class, $result);
$this->assertInstanceOf(SandboxLivenessCheck::class, $result);

$this->assertJsonStringEqualsJsonString(
json_encode([
'result' => [
'report' => [
'recommendation' => $this->recommendationMock,
'breakdown' => [
$this->breakdownMock
],
],
],
'liveness_type' => 'STATIC',
]),
json_encode($result)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class SandboxZoomLivenessCheckBuilderTest extends TestCase
{

/**
* @var MockObject|SandboxRecommendation
*/
Expand Down
1 change: 0 additions & 1 deletion tests/DocScan/Request/SandboxTaskResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
class SandboxTaskResultsTest extends TestCase
{

/**
* @test
* @covers ::__construct
Expand Down

0 comments on commit 77213a7

Please sign in to comment.