diff --git a/src/Faker/Provider/pt_PT/PhoneNumber.php b/src/Faker/Provider/pt_PT/PhoneNumber.php index 6dc69906..f85f3901 100644 --- a/src/Faker/Provider/pt_PT/PhoneNumber.php +++ b/src/Faker/Provider/pt_PT/PhoneNumber.php @@ -4,6 +4,9 @@ namespace Faker\Provider\pt_PT; class PhoneNumber extends \Faker\Provider\PhoneNumber { + /* + * @link http://en.wikipedia.org/wiki/Telephone_numbers_in_Portugal + */ protected static $phoneNumberPrefixes = array( 'Abrantes' => '241', 'Angra do HeroĆsmo' => '295', @@ -58,35 +61,27 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber 'Viseu' => '232', ); - protected static $mobileFormats = array( - '91#######', - '92#######', - '93#######', - '96#######', + protected static $mobileNumberPrefixes = array( + '91#', + '92#', + '93#', + '96#', ); protected static $countryCode = '+351'; - public static function phoneNumber($allowCountryCodePrefix = true) + public static function phoneNumber() { - $format = static::randomElement(static::$phoneNumberPrefixes).'######'; + $elements = array_merge(static::$phoneNumberPrefixes, static::$mobileNumberPrefixes); + $format = static::randomElement($elements).'######'; - if ($allowCountryCodePrefix) { - return static::numerify(static::randomElement(array(static::$countryCode, '')).$format); - } - - return static::numerify($format); + return static::numerify(static::randomElement(array(static::$countryCode, '')).$format); } - public static function mobileNumber($allowCountryCodePrefix = true) + public static function mobileNumber() { - $format = static::numerify(static::randomElement(static::$mobileFormats)); + $format = static::randomElement(static::$mobileNumberPrefixes).'######'; - if ($allowCountryCodePrefix) { - return static::numerify(static::randomElement(array(static::$countryCode, '')).$format); - } - - return static::numerify($format); - + return static::numerify(static::randomElement(array(static::$countryCode, '')).$format); } } diff --git a/test/Faker/Provider/pt_PT/PhoneNumberTest.php b/test/Faker/Provider/pt_PT/PhoneNumberTest.php index ab8f5693..1ae51c90 100644 --- a/test/Faker/Provider/pt_PT/PhoneNumberTest.php +++ b/test/Faker/Provider/pt_PT/PhoneNumberTest.php @@ -16,18 +16,10 @@ class PhoneNumberTest extends \PHPUnit_Framework_TestCase public function testPhoneNumberReturnsPhoneNumberWithOrWithoutPrefix() { - $this->assertRegExp('/^([0-9]{9})|(\+351[0-9]{9})/', $this->faker->phoneNumber()); + $this->assertRegExp('/^(9[1,2,3,6][0-9]{7})|(2[0-9]{8})|(\+351[2][0-9]{8})|(\+3519[1,2,3,6][0-9]{7})/', $this->faker->phoneNumber()); } public function testMobileNumberReturnsMobileNumberWithOrWithoutPrefix() { - $this->assertRegExp('/^([0-9]{9})|(\+351[0-9]{9})/', $this->faker->mobileNumber()); - } - public function testPhoneNumberReturnsPhoneNumberWithoutPrefix() - { - $this->assertRegExp('/^([0-9]{9})/', $this->faker->phoneNumber(false)); - } - public function testMobileNumberReturnsMobileNumberWithoutPrefix() - { - $this->assertRegExp('/^([0-9]{9})/', $this->faker->mobileNumber(false)); + $this->assertRegExp('/^(9[1,2,3,6][0-9]{7})|(\+3519[1,2,3,6][0-9]{7})/', $this->faker->mobileNumber()); } }