Skip to content

Commit

Permalink
SDK-2265 added missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet-yoti committed Jun 20, 2024
1 parent 7e4c333 commit 0931fc9
Show file tree
Hide file tree
Showing 50 changed files with 3,688 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache

Large diffs are not rendered by default.

21 changes: 1 addition & 20 deletions src/DocScan/Session/Create/SdkConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ class SdkConfig implements \JsonSerializable
*/
private $attemptsConfiguration;

/**
* @var string|null
*/
private $biometricConsentFlow;

/**
* @param string|null $allowedCaptureMethods
* @param string|null $primaryColour
Expand All @@ -80,7 +75,6 @@ class SdkConfig implements \JsonSerializable
* @param string|null $privacyPolicyUrl
* @param bool|null $allowHandoff
* @param array<string, int>|null $idDocumentTextDataExtractionRetriesConfig
* @param string|null $biometricConsentFlow
*/
public function __construct(
?string $allowedCaptureMethods,
Expand All @@ -93,9 +87,7 @@ public function __construct(
?string $errorUrl,
?string $privacyPolicyUrl = null,
?bool $allowHandoff = null,
?array $idDocumentTextDataExtractionRetriesConfig = null,
?string $biometricConsentFlow = null

?array $idDocumentTextDataExtractionRetriesConfig = null
) {
$this->allowedCaptureMethods = $allowedCaptureMethods;
$this->primaryColour = $primaryColour;
Expand All @@ -110,8 +102,6 @@ public function __construct(
if (!is_null($idDocumentTextDataExtractionRetriesConfig)) {
$this->attemptsConfiguration = new AttemptsConfiguration($idDocumentTextDataExtractionRetriesConfig);
}
$this->biometricConsentFlow = $biometricConsentFlow;

}

/**
Expand All @@ -131,7 +121,6 @@ public function jsonSerialize(): \stdClass
'privacy_policy_url' => $this->getPrivacyPolicyUrl(),
'allow_handoff' => $this->getAllowHandoff(),
'attempts_configuration' => $this->getAttemptsConfiguration(),
'biometric_consent_flow' => $this->getBiometricConsentFlow()
]);
}

Expand Down Expand Up @@ -222,12 +211,4 @@ public function getAttemptsConfiguration(): ?AttemptsConfiguration
{
return $this->attemptsConfiguration;
}

/**
* @return string|null
*/
public function getBiometricConsentFlow(): ?string
{
return $this->biometricConsentFlow;
}
}
13 changes: 1 addition & 12 deletions src/DocScan/Session/Create/SdkConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ class SdkConfigBuilder
*/
private $idDocumentTextDataExtractionRetriesConfig;

/**
* @var string|null
*/
private $biometricConsentFlow;

public function withAllowsCamera(): self
{
return $this->withAllowedCaptureMethod(self::CAMERA);
Expand Down Expand Up @@ -141,11 +136,6 @@ public function withAllowHandoff(bool $allowHandoff): self
return $this;
}

public function withBiometricConsentFlow(string $biometricConsentFlow): self
{
$this->biometricConsentFlow = $biometricConsentFlow;
return $this;
}
/**
* Allows configuring the number of attempts permitted for text extraction on an ID document
*
Expand Down Expand Up @@ -213,8 +203,7 @@ public function build(): SdkConfig
$this->errorUrl,
$this->privacyPolicyUrl,
$this->allowHandoff,
$this->idDocumentTextDataExtractionRetriesConfig,
$this->biometricConsentFlow
$this->idDocumentTextDataExtractionRetriesConfig
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,14 @@ public function withManualCheck(string $manualCheck): self
return $this->setManualCheck($manualCheck);
}

/**
* @var bool
*/
private $createExpandedDocumentFields;

/**
*
* @param string $createExpandedDocumentFields
*
* @return $this
*/
public function withCreateExpandedDocumentFields(bool $createExpandedDocumentFields): self
{
$this->createExpandedDocumentFields = $createExpandedDocumentFields;
return $this;
}

/**
* @return RequestedTextExtractionTask
*/
public function build(): RequestedTextExtractionTask
{
Validation::notEmptyString($this->manualCheck, 'manualCheck');

$config = new RequestedTextExtractionTaskConfig($this->manualCheck, $this->chipData,
$this->createExpandedDocumentFields);
$config = new RequestedTextExtractionTaskConfig($this->manualCheck, $this->chipData);
return new RequestedTextExtractionTask($config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,14 @@ class RequestedTextExtractionTaskConfig implements RequestedTaskConfigInterface
*/
private $chipData;

/**
* @var bool|null
*/
private $createExpandedDocumentFields;

/**
* @param string $manualCheck
* @param string|null $chipData
* @param bool|null $createExpandedDocumentFields
*/
public function __construct(string $manualCheck, ?string $chipData = null, ?bool $createExpandedDocumentFields = false)
public function __construct(string $manualCheck, ?string $chipData = null)
{
$this->manualCheck = $manualCheck;
$this->chipData = $chipData;
$this->createExpandedDocumentFields = $createExpandedDocumentFields;
}

/**
Expand All @@ -44,7 +37,6 @@ public function jsonSerialize(): stdClass
return (object)Json::withoutNullValues([
'manual_check' => $this->getManualCheck(),
'chip_data' => $this->getChipData(),
'create_expanded_document_fields' => $this->getCreateExpandedDocumentFields(),
]);
}

Expand All @@ -63,12 +55,4 @@ public function getChipData(): ?string
{
return $this->chipData;
}

/**
* @return bool
*/
public function getCreateExpandedDocumentFields(): ?bool
{
return $this->createExpandedDocumentFields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(array $searchConfig)
$this->apiKey = $searchConfig['api_key'];
$this->monitoring = $searchConfig['monitoring'];
$this->clientRef = $searchConfig['client_ref'];
$this->tags = array_key_exists('tags', $searchConfig) ? json_decode($searchConfig['tags'], true) : [];
$this->tags = json_decode($searchConfig['tags'], true);
}

/**
Expand Down
17 changes: 0 additions & 17 deletions src/DocScan/Session/Retrieve/IdDocumentResourceResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ class IdDocumentResourceResponse extends ResourceResponse
*/
private $documentFields;

/**
* @var ExpandedDocumentFieldsResponse|null
*/
private $expandedDocumentFields;

/**
* @var DocumentIdPhotoResponse|null
*/
Expand All @@ -54,10 +49,6 @@ public function __construct(array $idDocument)
$this->documentFields = isset($idDocument['document_fields'])
? new DocumentFieldsResponse($idDocument['document_fields'])
: null;

$this->expandedDocumentFields = isset($idDocument['expanded_document_fields'])
? new ExpandedDocumentFieldsResponse($idDocument['expanded_document_fields'])
: null;

$this->documentIdPhoto = isset($idDocument['document_id_photo'])
? new DocumentIdPhotoResponse($idDocument['document_id_photo'])
Expand Down Expand Up @@ -96,14 +87,6 @@ public function getDocumentFields(): ?DocumentFieldsResponse
return $this->documentFields;
}

/**
* @return ExpandedDocumentFieldsResponse|null
*/
public function getExpandedDocumentFields(): ?ExpandedDocumentFieldsResponse
{
return $this->expandedDocumentFields;
}

/**
* @return DocumentIdPhotoResponse|null
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Identity/Constraint/Constraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Yoti\Identity\Constraint;

interface Constraint
{
public function getType(): string;
}
54 changes: 54 additions & 0 deletions src/Identity/Constraint/PreferredSources.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Yoti\Identity\Constraint;

use stdClass;
use Yoti\Identity\Policy\WantedAnchor;
use Yoti\Util\Validation;

class PreferredSources implements \JsonSerializable
{
/**
* @var WantedAnchor[]
*/
private array $wantedAnchors;

private bool $softPreference;

/**
* @param WantedAnchor[] $wantedAnchors
* @param bool $softPreference
*/
public function __construct(array $wantedAnchors, bool $softPreference)
{
Validation::isArrayOfType($wantedAnchors, [WantedAnchor::class], 'anchors');
$this->wantedAnchors = $wantedAnchors;

Validation::isBoolean($softPreference, 'soft_preference');
$this->softPreference = $softPreference;
}

public function jsonSerialize(): stdClass
{
return (object)[
'anchors' => $this->wantedAnchors,
'soft_preference' => $this->softPreference,
];
}

/**
* @return WantedAnchor[]
*/
public function getWantedAnchors(): array
{
return $this->wantedAnchors;
}

/**
* @return bool
*/
public function isSoftPreference(): bool
{
return $this->softPreference;
}
}
43 changes: 43 additions & 0 deletions src/Identity/Constraint/SourceConstraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Yoti\Identity\Constraint;

use Yoti\Identity\Policy\WantedAnchor;
use Yoti\Util\Validation;

class SourceConstraint implements \JsonSerializable, Constraint
{
private string $type;

private PreferredSources $preferredSources;

/**
* @param WantedAnchor[] $wantedAnchors
* @param bool $softPreference
*/
public function __construct(array $wantedAnchors, bool $softPreference)
{
$this->type = 'SOURCE';

Validation::isArrayOfType($wantedAnchors, [WantedAnchor::class], 'anchors');
$this->preferredSources = new PreferredSources($wantedAnchors, $softPreference);
}

public function getType(): string
{
return $this->type;
}

public function getPreferredSources(): PreferredSources
{
return $this->preferredSources;
}

public function jsonSerialize(): object
{
return (object)[
'type' => $this->getType(),
'preferred_sources' => $this->getPreferredSources(),
];
}
}
46 changes: 46 additions & 0 deletions src/Identity/Constraint/SourceConstraintBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Yoti\Identity\Constraint;

use Yoti\Identity\Policy\WantedAnchor;
use Yoti\Util\Validation;

class SourceConstraintBuilder
{
/**
* @var WantedAnchor[]
*/
private array $wantedAnchors = [];

private bool $softPreference = false;

/**
* @param WantedAnchor[] $wantedAnchors
*/
public function withWantedAnchors(array $wantedAnchors): self
{
Validation::isArrayOfType($wantedAnchors, [WantedAnchor::class], 'anchors');
$this->wantedAnchors = $wantedAnchors;

return $this;
}

public function withWantedAnchor(WantedAnchor $wantedAnchor): self
{
$this->wantedAnchors[] = $wantedAnchor;

return $this;
}

public function withSoftPreference(bool $softPreference): self
{
$this->softPreference = $softPreference;

return $this;
}

public function build(): SourceConstraint
{
return new SourceConstraint($this->wantedAnchors, $this->softPreference);
}
}
Loading

0 comments on commit 0931fc9

Please sign in to comment.