菜谱项目

PersonTest.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Faker\Test\Provider\en_ZA;
  3. use Faker\Generator;
  4. use Faker\Provider\en_ZA\Person;
  5. use Faker\Provider\DateTime;
  6. class PersonTest extends \PHPUnit_Framework_TestCase
  7. {
  8. private $faker;
  9. public function setUp()
  10. {
  11. $faker = new Generator();
  12. $faker->addProvider(new Person($faker));
  13. $faker->addProvider(new DateTime($faker));
  14. $this->faker = $faker;
  15. }
  16. public function testIdNumberWithDefaults()
  17. {
  18. $idNumber = $this->faker->idNumber();
  19. $this->assertEquals(13, strlen($idNumber));
  20. $this->assertRegExp('#^\d{13}$#', $idNumber);
  21. $this->assertInternalType('string', $idNumber);
  22. }
  23. public function testIdNumberForMales()
  24. {
  25. $idNumber = $this->faker->idNumber(new \DateTime(), true, 'male');
  26. $genderDigit = substr($idNumber, 6, 1);
  27. $this->assertContains($genderDigit, array('5', '6', '7', '8', '9'));
  28. }
  29. public function testIdNumberForFemales()
  30. {
  31. $idNumber = $this->faker->idNumber(new \DateTime(), true, 'female');
  32. $genderDigit = substr($idNumber, 6, 1);
  33. $this->assertContains($genderDigit, array('0', '1', '2', '3', '4'));
  34. }
  35. }