AddressTest.php 1.5 KB

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