Skip to content

Commit afc7497

Browse files
Moussa Sidibesidibos
authored andcommitted
SDK-603: Add AgeUnder/AgeOver setters for AgeVerification
1 parent 0fb2bcb commit afc7497

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

sandbox/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
// Make sure you run composer update inside the example folder before trying this example out
3+
// Make sure you run composer update inside the sandbox folder
44
require_once __DIR__ .'/vendor/autoload.php';
55

66
use Symfony\Component\Dotenv\Dotenv;

sandbox/src/Entity/SandboxAgeVerification.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class SandboxAgeVerification extends SandboxAttribute
88
{
9+
const AGE_OVER_FORMAT = 'age_over:%d';
10+
const AGE_UNDER_FORMAT = 'age_under:%d';
11+
912
public function __construct(\DateTime $dateObj, $derivation, array $anchors = [])
1013
{
1114
parent::__construct(
@@ -16,4 +19,14 @@ public function __construct(\DateTime $dateObj, $derivation, array $anchors = []
1619
$anchors
1720
);
1821
}
22+
23+
public function setAgeOver($age)
24+
{
25+
$this->derivation = sprintf(self::AGE_OVER_FORMAT, $age);
26+
}
27+
28+
public function setAgeUnder($age)
29+
{
30+
$this->derivation = sprintf(self::AGE_UNDER_FORMAT, $age);
31+
}
1932
}

sandbox/src/Entity/SandboxAttribute.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
class SandboxAttribute
55
{
6-
private $name;
7-
private $value;
8-
private $derivation;
9-
private $optional;
10-
private $anchors;
6+
protected $name;
7+
protected $value;
8+
protected $derivation;
9+
protected $optional;
10+
protected $anchors;
1111

1212
public function __construct($name, $value, $derivation = '', $optional = 'false', array $anchors = [])
1313
{

sandbox/tests/Entity/SandboxAgeVerificationTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function setUp()
1818
$dateTime = (new \DateTime())->setTimestamp(1171502725);
1919
$this->ageVerification = new SandboxAgeVerification(
2020
$dateTime,
21-
'age_under'
21+
'age_under:18'
2222
);
2323
}
2424

@@ -37,7 +37,7 @@ public function testGetValue()
3737

3838
public function testGetDerivation()
3939
{
40-
$this->assertEquals('age_under', $this->ageVerification->getDerivation());
40+
$this->assertEquals('age_under:18', $this->ageVerification->getDerivation());
4141
}
4242

4343
public function testGetOptional()
@@ -52,4 +52,18 @@ public function testGetAnchors()
5252
json_encode($this->ageVerification->getAnchors())
5353
);
5454
}
55+
56+
public function testGetAgeOver()
57+
{
58+
$ageVerification = clone $this->ageVerification;
59+
$ageVerification->setAgeOver(20);
60+
$this->assertEquals('age_over:20', $ageVerification->getDerivation());
61+
}
62+
63+
public function testAgeUnder()
64+
{
65+
$ageVerification = clone $this->ageVerification;
66+
$ageVerification->setAgeUnder(18);
67+
$this->assertEquals('age_under:18', $ageVerification->getDerivation());
68+
}
5569
}

0 commit comments

Comments
 (0)