菜谱项目

PhoneNumberTest.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Faker\Test\Provider\en_SG;
  3. use Faker\Factory;
  4. use Faker\Provider\en_SG\PhoneNumber;
  5. class PhoneNumberTest extends \PHPUnit_Framework_TestCase
  6. {
  7. private $faker;
  8. public function setUp()
  9. {
  10. $this->faker = Factory::create('en_SG');
  11. $this->faker->seed(1);
  12. $this->faker->addProvider(new PhoneNumber($this->faker));
  13. }
  14. // http://en.wikipedia.org/wiki/Telephone_numbers_in_Singapore#Numbering_plan
  15. // y means 0 to 8 only
  16. // x means 0 to 9
  17. public function testMobilePhoneNumberStartWith9Returns9yxxxxxx()
  18. {
  19. $startsWith9 = false;
  20. while (!$startsWith9) {
  21. $mobileNumber = $this->faker->mobileNumber();
  22. $startsWith9 = preg_match('/^(\+65|65)?\s*9/', $mobileNumber);
  23. }
  24. $this->assertRegExp('/^(\+65|65)?\s*9\s*[0-8]{3}\s*\d{4}$/', $mobileNumber);
  25. }
  26. // http://en.wikipedia.org/wiki/Telephone_numbers_in_Singapore#Numbering_plan
  27. // z means 1 to 9 only
  28. // x means 0 to 9
  29. public function testMobilePhoneNumberStartWith7Or8Returns7Or8zxxxxxx()
  30. {
  31. $startsWith7Or8 = false;
  32. while (!$startsWith7Or8) {
  33. $mobileNumber = $this->faker->mobileNumber();
  34. $startsWith7Or8 = preg_match('/^(\+65|65)?\s*[7-8]/', $mobileNumber);
  35. }
  36. $this->assertRegExp('/^(\+65|65)?\s*[7-8]\s*[1-9]{3}\s*\d{4}$/', $mobileNumber);
  37. }
  38. }