1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-03-25 17:59:47 +01:00

fixed phoneNumber returns both fixed and mobile numbers and updated tests

This commit is contained in:
Hugo Fonseca 2014-04-13 22:42:25 +01:00
parent 0f369b5319
commit 258eb619af
2 changed files with 17 additions and 30 deletions

View File

@ -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);
}
}

View File

@ -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());
}
}