AddressTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Faker\Test\Provider\uk_UA;
  3. use Faker\Generator;
  4. use Faker\Provider\uk_UA\Address;
  5. use PHPUnit\Framework\TestCase;
  6. class AddressTest extends TestCase
  7. {
  8. /**
  9. * @var 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. public function testPostCodeIsValid()
  19. {
  20. $main = '[0-9]{5}';
  21. $pattern = "/^($main)|($main-[0-9]{3})+$/";
  22. $postcode = $this->faker->postcode;
  23. $this->assertRegExp($pattern, $postcode, 'Post code ' . $postcode . ' is wrong!');
  24. }
  25. public function testEmptySuffixes()
  26. {
  27. $this->assertEmpty($this->faker->citySuffix, 'City suffix should be empty!');
  28. $this->assertEmpty($this->faker->streetSuffix, 'Street suffix should be empty!');
  29. }
  30. public function testStreetCyrOnly()
  31. {
  32. $pattern = "/[0-9А-ЩЯІЇЄЮа-щяіїєюьIVXCM][0-9А-ЩЯІЇЄЮа-щяіїєюь \'-.]*[А-Яа-я.]/u";
  33. $streetName = $this->faker->streetName;
  34. $this->assertSame(
  35. preg_match($pattern, $streetName),
  36. 1,
  37. 'Street name ' . $streetName . ' is wrong!'
  38. );
  39. }
  40. public function testCityNameCyrOnly()
  41. {
  42. $pattern = "/[А-ЩЯІЇЄЮа-щяіїєюь][0-9А-ЩЯІЇЄЮа-щяіїєюь \'-]*[А-Яа-я]/u";
  43. $city = $this->faker->city;
  44. $this->assertSame(
  45. preg_match($pattern, $city),
  46. 1,
  47. 'City name ' . $city . ' is wrong!'
  48. );
  49. }
  50. public function testRegionNameCyrOnly()
  51. {
  52. $pattern = "/[А-ЩЯІЇЄЮ][А-ЩЯІЇЄЮа-щяіїєюь]*а$/u";
  53. $regionName = $this->faker->region;
  54. $this->assertSame(
  55. preg_match($pattern, $regionName),
  56. 1,
  57. 'Region name ' . $regionName . ' is wrong!'
  58. );
  59. }
  60. public function testCountryCyrOnly()
  61. {
  62. $pattern = "/[А-ЩЯІЇЄЮа-щяіїєюьIVXCM][А-ЩЯІЇЄЮа-щяіїєюь \'-]*[А-Яа-я.]/u";
  63. $country = $this->faker->country;
  64. $this->assertSame(
  65. preg_match($pattern, $country),
  66. 1,
  67. 'Country name ' . $country . ' is wrong!'
  68. );
  69. }
  70. }