菜谱项目

AddressTest.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Faker\Provider\en_CA;
  3. use Faker\Generator;
  4. use Faker\Provider\en_CA\Address;
  5. class AddressTest extends \PHPUnit_Framework_TestCase
  6. {
  7. /**
  8. * @var Faker\Generator
  9. */
  10. private $faker;
  11. public function setUp()
  12. {
  13. $faker = new Generator();
  14. $faker->addProvider(new Address($faker));
  15. $this->faker = $faker;
  16. }
  17. /**
  18. * Test the validity of province
  19. */
  20. public function testProvince()
  21. {
  22. $province = $this->faker->province();
  23. $this->assertNotEmpty($province);
  24. $this->assertInternalType('string', $province);
  25. $this->assertRegExp('/[A-Z][a-z]+/', $province);
  26. }
  27. /**
  28. * Test the validity of province abbreviation
  29. */
  30. public function testProvinceAbbr()
  31. {
  32. $provinceAbbr = $this->faker->provinceAbbr();
  33. $this->assertNotEmpty($provinceAbbr);
  34. $this->assertInternalType('string', $provinceAbbr);
  35. $this->assertRegExp('/^[A-Z]{2}$/', $provinceAbbr);
  36. }
  37. /**
  38. * Test the validity of postcode letter
  39. */
  40. public function testPostcodeLetter()
  41. {
  42. $postcodeLetter = $this->faker->randomPostcodeLetter();
  43. $this->assertNotEmpty($postcodeLetter);
  44. $this->assertInternalType('string', $postcodeLetter);
  45. $this->assertRegExp('/^[A-Z]{1}$/', $postcodeLetter);
  46. }
  47. /**
  48. * Test the validity of Canadian postcode
  49. */
  50. public function testPostcode()
  51. {
  52. $postcode = $this->faker->postcode();
  53. $this->assertNotEmpty($postcode);
  54. $this->assertInternalType('string', $postcode);
  55. $this->assertRegExp('/^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$/', $postcode);
  56. }
  57. }
  58. ?>