菜谱项目

PersonTest.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Faker\Test\Provider\en_US;
  3. use Faker\Provider\en_US\Person;
  4. use Faker\Generator;
  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. public function testSsn()
  18. {
  19. for ($i = 0; $i < 100; $i++) {
  20. $number = $this->faker->ssn;
  21. // should be in the format ###-##-####
  22. $this->assertRegExp('/^[0-9]{3}-[0-9]{2}-[0-9]{4}$/', $number);
  23. $parts = explode("-", $number);
  24. // first part must be between 001 and 899, excluding 666
  25. $this->assertNotEquals(666, $parts[0]);
  26. $this->assertGreaterThan(0, $parts[0]);
  27. $this->assertLessThan(900, $parts[0]);
  28. // second part must be between 01 and 99
  29. $this->assertGreaterThan(0, $parts[1]);
  30. $this->assertLessThan(100, $parts[1]);
  31. // the third part must be between 0001 and 9999
  32. $this->assertGreaterThan(0, $parts[2]);
  33. $this->assertLessThan(10000, $parts[2]);
  34. }
  35. }
  36. }