本文整理匯總了PHP中Faker\Generator::birthNumber方法的典型用法代碼示例。如果您正苦於以下問題:PHP Generator::birthNumber方法的具體用法?PHP Generator::birthNumber怎麽用?PHP Generator::birthNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Faker\Generator
的用法示例。
在下文中一共展示了Generator::birthNumber方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testBirthNumber
public function testBirthNumber()
{
$faker = new Generator();
$faker->addProvider(new Person($faker));
$faker->addProvider(new Miscellaneous($faker));
for ($i = 0; $i < 1000; $i++) {
$birthNumber = $faker->birthNumber();
$birthNumber = str_replace('/', '', $birthNumber);
// check date
$year = intval(substr($birthNumber, 0, 2), 10);
$month = intval(substr($birthNumber, 2, 2), 10);
$day = intval(substr($birthNumber, 4, 2), 10);
// 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;
}
$this->assertTrue(checkdate($month, $day, $year), "Birth number {$birthNumber}: date {$year}/{$month}/{$day} is invalid.");
// check CRC if presented
if (strlen($birthNumber) == 10) {
$crc = intval(substr($birthNumber, -1), 10);
$refCrc = intval(substr($birthNumber, 0, -1), 10) % 11;
if ($refCrc == 10) {
$refCrc = 0;
}
$this->assertEquals($crc, $refCrc, "Birth number {$birthNumber}: checksum {$crc} doesn't match expected {$refCrc}.");
}
}
}