1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
<?php
namespace Faker\Test\Provider\cs_CZ;
use Faker\Provider\cs_CZ\Person;
use Faker\Provider\Miscellaneous;
use Faker\Test\TestCase;
/**
* @group legacy
*/
final class PersonTest extends TestCase
{
public function testBirthNumber()
{
for ($i = 0; $i < 1000; ++$i) {
$birthNumber = $this->faker->birthNumber();
$birthNumber = str_replace('/', '', $birthNumber);
// check date
$year = (int) substr($birthNumber, 0, 2);
$month = (int) substr($birthNumber, 2, 2);
$day = (int) substr($birthNumber, 4, 2);
// make 4 digit year from 2 digit representation
$year += $year < 54 ? 2000 : 1900;
// adjust special cases for month
if ($month > 50) {
$month -= 50;
}
if ($year >= 2004 && $month > 20) {
$month -= 20;
}
self::assertTrue(checkdate($month, $day, $year), "Birth number $birthNumber: date $year/$month/$day is invalid.");
// check CRC if presented
if (strlen($birthNumber) == 10) {
$crc = (int) substr($birthNumber, -1);
$refCrc = (int) substr($birthNumber, 0, -1) % 11;
if ($refCrc == 10) {
$refCrc = 0;
}
self::assertEquals($crc, $refCrc, "Birth number $birthNumber: checksum $crc doesn't match expected $refCrc.");
}
}
}
protected function getProviders(): iterable
{
yield new Person($this->faker);
yield new Miscellaneous($this->faker);
}
}
|