菜谱项目

PersonTest.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Faker\Test\Provider\zh_TW;
  3. use Faker\Generator;
  4. use Faker\Provider\zh_TW\Person;
  5. class PersonTest extends \PHPUnit_Framework_TestCase
  6. {
  7. /**
  8. * @var Generator
  9. */
  10. private $faker;
  11. public function setUp()
  12. {
  13. $faker = new Generator();
  14. $faker->addProvider(new Person($faker));
  15. $this->faker = $faker;
  16. }
  17. /**
  18. * @see https://zh.wikipedia.org/wiki/%E4%B8%AD%E8%8F%AF%E6%B0%91%E5%9C%8B%E5%9C%8B%E6%B0%91%E8%BA%AB%E5%88%86%E8%AD%89
  19. */
  20. public function testPersonalIdentityNumber()
  21. {
  22. $id = $this->faker->personalIdentityNumber;
  23. $firstChar = substr($id, 0, 1);
  24. $codesString = Person::$idBirthplaceCode[$firstChar] . substr($id, 1);
  25. // After transfer the first alphabet word into 2 digit number, there should be totally 11 numbers
  26. $this->assertRegExp("/^[0-9]{11}$/", $codesString);
  27. $total = 0;
  28. $codesArray = str_split($codesString);
  29. foreach ($codesArray as $key => $code) {
  30. $total += $code * Person::$idDigitValidator[$key];
  31. }
  32. // Validate
  33. $this->assertEquals(0, ($total % 10));
  34. }
  35. }