|
11 | 11 | */ |
12 | 12 | final class PersonTest extends TestCase |
13 | 13 | { |
| 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 | + */ |
14 | 19 | public function testIndividualIdentificationNumberIsValid() |
15 | 20 | { |
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); |
21 | 50 | } |
22 | 51 |
|
23 | 52 | protected function getProviders(): iterable |
|
0 commit comments