Skip to content

Commit fc310fe

Browse files
Rodion LiuboretsLuborRod
authored andcommitted
Add logic and tests
1 parent 77f751d commit fc310fe

7 files changed

+244
-9
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Create\Check;
4+
5+
use Yoti\DocScan\Session\Create\Filters\DocumentFilter;
6+
7+
class IssuingAuthoritySubCheck
8+
{
9+
/**
10+
* @var bool|null
11+
*/
12+
private $requested;
13+
14+
/**
15+
* Returns the {@link DocumentFilter} that will drive which
16+
* documents the sub check is performed on
17+
*
18+
* @var DocumentFilter|null
19+
*/
20+
private $filter;
21+
22+
/**
23+
* @param bool|null $requested
24+
* @param DocumentFilter|null $documentFilter
25+
*/
26+
public function __construct(?bool $requested, ?DocumentFilter $documentFilter)
27+
{
28+
$this->requested = $requested;
29+
$this->filter = $documentFilter;
30+
}
31+
32+
/**
33+
* Returns if the issuing authority sub check has been requested
34+
*
35+
* @return bool|null
36+
*/
37+
public function isRequested(): ?bool
38+
{
39+
return $this->requested;
40+
}
41+
42+
/**
43+
* @return DocumentFilter|null
44+
*/
45+
public function getFilter(): ?DocumentFilter
46+
{
47+
return $this->filter;
48+
}
49+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Yoti\DocScan\Session\Create\Check;
4+
5+
use Yoti\DocScan\Session\Create\Filters\DocumentFilter;
6+
7+
class IssuingAuthoritySubCheckBuilder
8+
{
9+
/**
10+
* @var bool
11+
*/
12+
private $requested;
13+
14+
/**
15+
* Returns the {@link DocumentFilter} that will drive which
16+
* documents the sub check is performed on
17+
*
18+
* @var DocumentFilter
19+
*/
20+
private $filter;
21+
22+
/**
23+
* @param bool $requested
24+
* @return $this
25+
*/
26+
public function withRequested(bool $requested): IssuingAuthoritySubCheckBuilder
27+
{
28+
$this->requested = $requested;
29+
30+
return $this;
31+
}
32+
33+
/**
34+
* @param DocumentFilter $filter
35+
* @return $this
36+
*/
37+
public function withDocumentFilter(DocumentFilter $filter): IssuingAuthoritySubCheckBuilder
38+
{
39+
$this->filter = $filter;
40+
41+
return $this;
42+
}
43+
44+
/**
45+
* @return IssuingAuthoritySubCheck
46+
*/
47+
public function build(): IssuingAuthoritySubCheck
48+
{
49+
return new IssuingAuthoritySubCheck($this->requested, $this->filter);
50+
}
51+
}

src/DocScan/Session/Create/Check/RequestedDocumentAuthenticityCheck.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public function __construct(?RequestedDocumentAuthenticityCheckConfig $config =
2121
/**
2222
* @inheritDoc
2323
*/
24-
protected function getType(): string
24+
public function getType(): string
2525
{
2626
return Constants::ID_DOCUMENT_AUTHENTICITY;
2727
}
2828

2929
/**
3030
* @inheritDoc
3131
*/
32-
protected function getConfig(): ?RequestedCheckConfigInterface
32+
public function getConfig(): ?RequestedCheckConfigInterface
3333
{
3434
return $this->config;
3535
}

src/DocScan/Session/Create/Check/RequestedDocumentAuthenticityCheckBuilder.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,51 @@
44

55
namespace Yoti\DocScan\Session\Create\Check;
66

7+
use Yoti\DocScan\Session\Create\Filters\DocumentFilter;
78
use Yoti\DocScan\Session\Create\Traits\Builder\ManualCheckTrait;
89

910
class RequestedDocumentAuthenticityCheckBuilder
1011
{
1112
use ManualCheckTrait;
1213

14+
/**
15+
* @var IssuingAuthoritySubCheck|null
16+
*/
17+
private $issuingAuthoritySubCheck;
18+
19+
/**
20+
* @return $this
21+
*/
22+
public function withIssuingAuthoritySubCheck(): RequestedDocumentAuthenticityCheckBuilder
23+
{
24+
$this->issuingAuthoritySubCheck = (new IssuingAuthoritySubCheckBuilder())
25+
->withRequested(true)
26+
->build();
27+
28+
return $this;
29+
}
30+
31+
/**
32+
* @param DocumentFilter $filter
33+
* @return $this
34+
*/
35+
public function withIssuingAuthoritySubCheckAndDocumentFilter(
36+
DocumentFilter $filter
37+
): RequestedDocumentAuthenticityCheckBuilder {
38+
$this->issuingAuthoritySubCheck = (new IssuingAuthoritySubCheckBuilder())
39+
->withRequested(true)
40+
->withDocumentFilter($filter)
41+
->build();
42+
43+
return $this;
44+
}
45+
46+
/**
47+
* @return RequestedDocumentAuthenticityCheck
48+
*/
1349
public function build(): RequestedDocumentAuthenticityCheck
1450
{
15-
$config = new RequestedDocumentAuthenticityCheckConfig($this->manualCheck);
51+
$config = new RequestedDocumentAuthenticityCheckConfig($this->manualCheck, $this->issuingAuthoritySubCheck);
1652
return new RequestedDocumentAuthenticityCheck($config);
1753
}
1854
}

src/DocScan/Session/Create/Check/RequestedDocumentAuthenticityCheckConfig.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ class RequestedDocumentAuthenticityCheckConfig implements RequestedCheckConfigIn
1313
*/
1414
private $manualCheck;
1515

16-
public function __construct(?string $manualCheck)
16+
/**
17+
* @var IssuingAuthoritySubCheck|null
18+
*/
19+
private $issuingAuthoritySubCheck;
20+
21+
/**
22+
* @param string|null $manualCheck
23+
* @param IssuingAuthoritySubCheck|null $issuingAuthoritySubCheck
24+
*/
25+
public function __construct(?string $manualCheck, ?IssuingAuthoritySubCheck $issuingAuthoritySubCheck = null)
1726
{
1827
$this->manualCheck = $manualCheck;
28+
$this->issuingAuthoritySubCheck = $issuingAuthoritySubCheck;
1929
}
2030

2131
/**
@@ -25,6 +35,7 @@ public function jsonSerialize(): \stdClass
2535
{
2636
return (object) Json::withoutNullValues([
2737
'manual_check' => $this->getManualCheck(),
38+
'issuing_authority_sub_check' => $this->getIssuingAuthoritySubCheck(),
2839
]);
2940
}
3041

@@ -35,4 +46,12 @@ public function getManualCheck(): ?string
3546
{
3647
return $this->manualCheck;
3748
}
49+
50+
/**
51+
* @return IssuingAuthoritySubCheck|null
52+
*/
53+
public function getIssuingAuthoritySubCheck(): ?IssuingAuthoritySubCheck
54+
{
55+
return $this->issuingAuthoritySubCheck;
56+
}
3857
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Yoti\Test\DocScan\Session\Create\Check;
4+
5+
use Yoti\DocScan\Session\Create\Check\IssuingAuthoritySubCheckBuilder;
6+
use Yoti\DocScan\Session\Create\Filters\DocumentFilter;
7+
use Yoti\Test\TestCase;
8+
9+
/**
10+
* @coversDefaultClass \Yoti\DocScan\Session\Create\Check\IssuingAuthoritySubCheck
11+
*/
12+
class IssuingAuthoritySubCheckTest extends TestCase
13+
{
14+
/**
15+
* @test
16+
* @covers ::__construct
17+
* @covers ::isRequested
18+
* @covers \Yoti\DocScan\Session\Create\Check\IssuingAuthoritySubCheckBuilder::withDocumentFilter
19+
* @covers \Yoti\DocScan\Session\Create\Check\IssuingAuthoritySubCheckBuilder::withRequested
20+
* @covers \Yoti\DocScan\Session\Create\Check\IssuingAuthoritySubCheckBuilder::build
21+
*/
22+
public function withRequestedAndDocumentFilterShouldSetTheValueCorrectly()
23+
{
24+
$documentFilterMock = $this->getMockForAbstractClass(DocumentFilter::class, ['type' => 'some']);
25+
26+
$result = (new IssuingAuthoritySubCheckBuilder())
27+
->withRequested(true)
28+
->withDocumentFilter($documentFilterMock)
29+
->build();
30+
31+
$this->assertTrue($result->isRequested());
32+
$this->assertInstanceOf(DocumentFilter::class, $result->getFilter());
33+
}
34+
}

tests/DocScan/Session/Create/Check/RequestedDocumentAuthenticityCheckBuilderTest.php

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Yoti\DocScan\Session\Create\Check\RequestedDocumentAuthenticityCheck;
66
use Yoti\DocScan\Session\Create\Check\RequestedDocumentAuthenticityCheckBuilder;
7+
use Yoti\DocScan\Session\Create\Check\RequestedDocumentAuthenticityCheckConfig;
8+
use Yoti\DocScan\Session\Create\Filters\DocumentFilter;
79
use Yoti\Test\TestCase;
810

911
/**
@@ -40,7 +42,7 @@ public function shouldJsonEncodeCorrectly()
4042
->build();
4143

4244
$expected = [
43-
'config' => (object) [],
45+
'config' => (object)[],
4446
'type' => 'ID_DOCUMENT_AUTHENTICITY',
4547
];
4648

@@ -57,7 +59,7 @@ public function shouldCreateCorrectString()
5759
->build();
5860

5961
$expected = [
60-
'config' => (object) [],
62+
'config' => (object)[],
6163
'type' => 'ID_DOCUMENT_AUTHENTICITY',
6264
];
6365

@@ -77,7 +79,7 @@ public function shouldJsonEncodeCorrectlyWithManualCheckAlways()
7779
->build();
7880

7981
$expected = [
80-
'config' => (object) [
82+
'config' => (object)[
8183
'manual_check' => 'ALWAYS',
8284
],
8385
'type' => 'ID_DOCUMENT_AUTHENTICITY',
@@ -99,7 +101,7 @@ public function shouldJsonEncodeCorrectlyWithManualCheckNever()
99101
->build();
100102

101103
$expected = [
102-
'config' => (object) [
104+
'config' => (object)[
103105
'manual_check' => 'NEVER',
104106
],
105107
'type' => 'ID_DOCUMENT_AUTHENTICITY',
@@ -121,12 +123,56 @@ public function shouldJsonEncodeCorrectlyWithManualCheckFallback()
121123
->build();
122124

123125
$expected = [
124-
'config' => (object) [
126+
'config' => (object)[
125127
'manual_check' => 'FALLBACK',
126128
],
127129
'type' => 'ID_DOCUMENT_AUTHENTICITY',
128130
];
129131

130132
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($result));
131133
}
134+
135+
/**
136+
* @test
137+
* @covers ::withIssuingAuthoritySubCheck
138+
* @covers ::build
139+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedDocumentAuthenticityCheck::__construct
140+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedDocumentAuthenticityCheck::getConfig
141+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedDocumentAuthenticityCheckConfig::getIssuingAuthoritySubCheck
142+
*/
143+
public function withIssuingAuthoritySubCheckShouldBuildDefaultObject()
144+
{
145+
$result = (new RequestedDocumentAuthenticityCheckBuilder())
146+
->withIssuingAuthoritySubCheck()
147+
->build();
148+
149+
/** @var RequestedDocumentAuthenticityCheckConfig $config */
150+
$config = $result->getConfig();
151+
152+
$this->assertTrue($config->getIssuingAuthoritySubCheck()->isRequested());
153+
$this->assertNull($config->getIssuingAuthoritySubCheck()->getFilter());
154+
}
155+
156+
/**
157+
* @test
158+
* @covers ::withIssuingAuthoritySubCheckAndDocumentFilter
159+
* @covers ::build
160+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedDocumentAuthenticityCheck::__construct
161+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedDocumentAuthenticityCheck::getConfig
162+
* @covers \Yoti\DocScan\Session\Create\Check\RequestedDocumentAuthenticityCheckConfig::getIssuingAuthoritySubCheck
163+
*/
164+
public function withIssuingAuthoritySubCheckShouldAcceptDocumentFilter()
165+
{
166+
$documentFilterMock = $this->getMockForAbstractClass(DocumentFilter::class, ['type']);
167+
168+
$result = (new RequestedDocumentAuthenticityCheckBuilder())
169+
->withIssuingAuthoritySubCheckAndDocumentFilter($documentFilterMock)
170+
->build();
171+
172+
/** @var RequestedDocumentAuthenticityCheckConfig $config */
173+
$config = $result->getConfig();
174+
175+
$this->assertTrue($config->getIssuingAuthoritySubCheck()->isRequested());
176+
$this->assertInstanceOf(DocumentFilter::class, $config->getIssuingAuthoritySubCheck()->getFilter());
177+
}
132178
}

0 commit comments

Comments
 (0)