Skip to content

Commit c8e4f9c

Browse files
committed
AgeInfo: finished code, added unit test.
1 parent 325ddbf commit c8e4f9c

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

src/org/nameapi/ontology/input/entities/person/age/AgeInfo.php

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,46 @@
22

33
namespace org\nameapi\ontology\input\entities\person\age;
44

5+
/**
6+
* Use the AgeInfoFactory to create one.
7+
*/
58
class AgeInfo {
69

710
/**
811
* @var int $birthDay
912
*/
10-
public $birthDay = null;
13+
private $birthDay = null;
1114

1215
/**
1316
* @var int $birthMonth
1417
*/
15-
public $birthMonth = null;
18+
private $birthMonth = null;
1619

1720
/**
1821
* @var int $birthYear
1922
*/
20-
public $birthYear = null;
23+
private $birthYear = null;
2124

2225
/**
2326
* @var int[] $birthYearRange
2427
*/
25-
public $birthYearRange = null;
28+
private $birthYearRange = null;
2629

2730
/**
28-
* @param int $birthDay
29-
* @param int $birthMonth
3031
* @param int $birthYear
32+
* @param int $birthMonth
33+
* @param int $birthDay
3134
* @param int[] $birthYearRange
32-
* @throws Exception on invalid input data
35+
* @throws \Exception on invalid input data
3336
* @access public
3437
*/
35-
public function __construct($birthDay, $birthMonth, $birthYear, $birthYearRange) {
36-
if ($birthDay!=null && ($birthYear<0 || $birthYear>2100)) throw new \Exception("Year is out of legal range: "+$birthYear+"!");
37-
if ($birthMonth!=null && ($birthMonth<1 || $birthMonth>12)) throw new \Exception("Month must be 1-12 but was: "+$birthMonth+"!");
38-
if ($birthDay!=null && ($birthDay<1 || $birthDay>31)) throw new \Exception("Day must be 1-31 but was: "+$birthDay+"!");
38+
public function __construct($birthYear, $birthMonth, $birthDay, $birthYearRange) {
39+
if ($birthDay!=null && ($birthYear<0 || $birthYear>2100)) throw new \Exception("Year is out of legal range: ".$birthYear."!");
40+
if ($birthMonth!=null && ($birthMonth<1 || $birthMonth>12)) throw new \Exception("Month must be 1-12 but was: ".$birthMonth."!");
41+
if ($birthDay!=null && ($birthDay<1 || $birthDay>31)) throw new \Exception("Day must be 1-31 but was: ".$birthDay."!");
3942
if ($birthYearRange!=null && ($birthYearRange[0]!=null && $birthYearRange[1]!=null)) {
4043
if ($birthYearRange[0] > $birthYearRange[1]) {
41-
throw new \Exception("Year end may not be before year start but it was: start="+$birthYearRange[0]+" end="+$birthYearRange[1]+"!");
44+
throw new \Exception("Year end may not be before year start but it was: start=".$birthYearRange[0]." end=".$birthYearRange[1]."!");
4245
}
4346
}
4447
$this->birthDay = $birthDay;
@@ -53,37 +56,19 @@ public function __construct($birthDay, $birthMonth, $birthYear, $birthYearRange)
5356
public function getBirthDay() {
5457
return $this->birthDay;
5558
}
56-
// /**
57-
// * @param int $birthDay
58-
// */
59-
// public function setBirthDay($birthDay) {
60-
// $this->birthDay = $birthDay;
61-
// }
6259

6360
/**
6461
* @return int
6562
*/
6663
public function getBirthMonth() {
6764
return $this->birthMonth;
6865
}
69-
// /**
70-
// * @param int $birthMonth
71-
// */
72-
// public function setBirthMonth($birthMonth) {
73-
// $this->birthMonth = $birthMonth;
74-
// }
7566

7667
/**
7768
* @return int
7869
*/
7970
public function getBirthYear() {
8071
return $this->birthYear;
8172
}
82-
// /**
83-
// * @param int $birthYear
84-
// */
85-
// public function setBirthYear($birthYear) {
86-
// $this->birthYear = $birthYear;
87-
// }
8873

8974
}

src/org/nameapi/ontology/input/entities/person/age/AgeInfoFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
include_once('AgeInfo.php');
66

7+
/**
8+
* Creates instances of {@link AgeInfo}.
9+
*/
710
class AgeInfoFactory {
811

912
/**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace org\nameapi\ontology\input\entities\person\age;
4+
5+
require_once(__DIR__.'/../../../../../../../../../src/org/nameapi/ontology/input/entities/person/age/AgeInfoFactory.php');
6+
7+
class AgeInfoFactoryTest extends \PHPUnit_Framework_TestCase {
8+
9+
public function testDate() {
10+
$ageInfo = AgeInfoFactory::forDate(1917, 5, 29);
11+
$this->assertEquals($ageInfo->getBirthDay(), 29);
12+
$this->assertEquals($ageInfo->getBirthMonth(), 5);
13+
$this->assertEquals($ageInfo->getBirthYear(), 1917);
14+
}
15+
16+
}

0 commit comments

Comments
 (0)