Skip to content

Commit a664100

Browse files
authored
Fix kk_KZ\Person::individualIdentificationNumber generation (#411)
1 parent fafead6 commit a664100

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

src/Faker/Provider/kk_KZ/Person.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,25 +176,29 @@ class Person extends \Faker\Provider\Person
176176
];
177177

178178
/**
179+
* Note! When calculating individual identification number
180+
* 2000-01-01 - 2000-12-31 counts as 21th century
181+
* 1900-01-01 - 1900-12-31 counts as 20th century
182+
*
179183
* @param int $year
180184
*
181-
* @return int|null
185+
* @return int
182186
*/
183187
private static function getCenturyByYear($year)
184188
{
185-
if ($year >= 2000 && $year <= DateTime::year()) {
189+
if (($year >= 2100) || ($year < 1800)) {
190+
throw new \InvalidArgumentException('Unexpected century');
191+
}
192+
193+
if ($year >= 2000) {
186194
return self::CENTURY_21ST;
187195
}
188196

189197
if ($year >= 1900) {
190198
return self::CENTURY_20TH;
191199
}
192200

193-
if ($year >= 1800) {
194-
return self::CENTURY_19TH;
195-
}
196-
197-
return null;
201+
return self::CENTURY_19TH;
198202
}
199203

200204
/**

test/Faker/Provider/kk_KZ/PersonTest.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,42 @@
1111
*/
1212
final class PersonTest extends TestCase
1313
{
14+
/**
15+
* Note! When calculating individual identification number
16+
* 2000-01-01 - 2000-12-31 counts as 21th century
17+
* 1900-01-01 - 1900-12-31 counts as 20th century
18+
*/
1419
public function testIndividualIdentificationNumberIsValid()
1520
{
16-
$birthDate = DateTime::dateTimeBetween('-30 years', '-10 years');
17-
$individualIdentificationNumber = $this->faker->individualIdentificationNumber($birthDate);
18-
$controlDigit = Person::checkSum($individualIdentificationNumber);
19-
20-
self::assertSame($controlDigit, (int) substr($individualIdentificationNumber, 11, 1));
21+
// 21st century.
22+
$birthDate = DateTime::dateTimeBetween('2000-01-01', '2099-12-31');
23+
$individualIdentificationNumber = $this->faker->individualIdentificationNumber($birthDate, Person::GENDER_MALE);
24+
self::assertSame(Person::MALE_CENTURY_21ST, (int) $individualIdentificationNumber[6]);
25+
self::assertSame(Person::checkSum($individualIdentificationNumber), (int) $individualIdentificationNumber[11]);
26+
$individualIdentificationNumber = $this->faker->individualIdentificationNumber($birthDate, Person::GENDER_FEMALE);
27+
self::assertSame(Person::FEMALE_CENTURY_21ST, (int) $individualIdentificationNumber[6]);
28+
self::assertSame(Person::checkSum($individualIdentificationNumber), (int) $individualIdentificationNumber[11]);
29+
// 20th century.
30+
$birthDate = DateTime::dateTimeBetween('1900-01-01', '1999-12-31');
31+
$individualIdentificationNumber = $this->faker->individualIdentificationNumber($birthDate, Person::GENDER_MALE);
32+
self::assertSame(Person::checkSum($individualIdentificationNumber), (int) $individualIdentificationNumber[11]);
33+
self::assertSame(Person::MALE_CENTURY_20TH, (int) $individualIdentificationNumber[6]);
34+
$individualIdentificationNumber = $this->faker->individualIdentificationNumber($birthDate, Person::GENDER_FEMALE);
35+
self::assertSame(Person::checkSum($individualIdentificationNumber), (int) $individualIdentificationNumber[11]);
36+
self::assertSame(Person::FEMALE_CENTURY_20TH, (int) $individualIdentificationNumber[6]);
37+
// 19th century.
38+
$birthDate = DateTime::dateTimeBetween('1800-01-01', '1899-12-31');
39+
$individualIdentificationNumber = $this->faker->individualIdentificationNumber($birthDate, Person::GENDER_MALE);
40+
self::assertSame(Person::checkSum($individualIdentificationNumber), (int) $individualIdentificationNumber[11]);
41+
self::assertSame(Person::MALE_CENTURY_19TH, (int) $individualIdentificationNumber[6]);
42+
$individualIdentificationNumber = $this->faker->individualIdentificationNumber($birthDate, Person::GENDER_FEMALE);
43+
self::assertSame(Person::checkSum($individualIdentificationNumber), (int) $individualIdentificationNumber[11]);
44+
self::assertSame(Person::FEMALE_CENTURY_19TH, (int) $individualIdentificationNumber[6]);
45+
// 22th century
46+
self::expectException(\InvalidArgumentException::class);
47+
self::expectExceptionMessage('Unexpected century');
48+
$birthDate = DateTime::dateTimeBetween('2100-01-01', '2199-12-31');
49+
$this->faker->individualIdentificationNumber($birthDate);
2150
}
2251

2352
protected function getProviders(): iterable

0 commit comments

Comments
 (0)