菜谱项目

AddressTest.php 901B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Faker\Test\Provider\pt_PT;
  3. use Faker\Generator;
  4. use Faker\Provider\pt_PT\Address;
  5. use Faker\Provider\pt_PT\Person;
  6. class AddressTest extends \PHPUnit_Framework_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 = '[1-9]{1}[0-9]{2}[0,1,4,5,9]{1}';
  21. $pattern = "/^($main)|($main-[0-9]{3})+$/";
  22. $postcode = $this->faker->postcode();
  23. $this->assertSame(preg_match($pattern, $postcode), 1, $postcode);
  24. }
  25. public function testAddressIsSingleLine()
  26. {
  27. $this->faker->addProvider(new Person($this->faker));
  28. $address = $this->faker->address();
  29. $this->assertFalse(strstr($address, "\n"));
  30. }
  31. }