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

added pt_pt phone number and tests

This commit is contained in:
Hugo Fonseca 2014-04-11 23:33:44 +01:00
parent a277bf23f9
commit 40b2383bef
2 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,92 @@
<?php
namespace Faker\Provider\pt_PT;
class PhoneNumber extends \Faker\Provider\PhoneNumber
{
protected static $phoneNumberPrefixes = array(
'Abrantes' => '241',
'Angra do Heroísmo' => '295',
'Arganil' => '235',
'Aveiro' => '234',
'Beja' => '284',
'Braga' => '253',
'Bragança' => '273',
'Caldas da Rainha' => '262',
'Castelo Branco' => '272',
'Castro Verde' => '286',
'Chaves' => '276',
'Coimbra' => '239',
'Covilhã' => '275',
'Estremoz' => '268',
'Évora' => '266',
'Faro' => '289',
'Figueira da Foz' => '233',
'Funchal' => '291',
'Guarda' => '271',
'Horta' => '292',
'Idanha-a-Nova' => '277',
'Leiria' => '244',
'Lisboa' => '21#',
'Mealhada' => '231',
'Mirandela' => '278',
'Moncorvo' => '279',
'Moura' => '285',
'Odemira' => '283',
'Penafiel' => '255',
'Peso da Régua' => '254',
'Pombal' => '236',
'Ponta Delgada' => '296',
'Ponte de Sôr' => '242',
'Portalegre' => '245',
'Portimão' => '282',
'Porto' => '22#',
'Proença-a-Nova' => '274',
'S. João da Madeira' => '256',
'Santarém' => '243',
'Santiago do Cacém' => '269',
'Seia' => '238',
'Setúbal' => '265',
'Tavira' => '281',
'Torres Novas' => '249',
'Torres Vedras' => '261',
'Valença' => '251',
'Viana do Castelo' => '258',
'Vila Franca de Xira' => '263',
'V. N. de Famalicão' => '252',
'Vila Real' => '259',
'Viseu' => '232',
);
protected static $mobileFormats = array(
'91#######',
'92#######',
'93#######',
'96#######',
);
protected static $countryCode = '+351';
public static function phoneNumber($allowCountryCodePrefix = true)
{
$format = static::randomElement(static::$phoneNumberPrefixes).'######';
if ($allowCountryCodePrefix) {
return static::numerify(static::randomElement(array(static::$countryCode, '')).$format);
}
return static::numerify($format);
}
public static function mobileNumber($allowCountryCodePrefix = true)
{
$format = static::numerify(static::randomElement(static::$mobileFormats));
if ($allowCountryCodePrefix) {
return static::numerify(static::randomElement(array(static::$countryCode, '')).$format);
}
return static::numerify($format);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace \Faker\Test\Provider\pt_PT;
use Faker\Generator;
use Faker\Provider\pt_PT\PhoneNumber;
class PhoneNumberTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$faker = new Generator();
$faker->addProvider(new PhoneNumber($faker));
$this->faker = $faker;
}
public function testPhoneNumberReturnsPhoneNumberWithOrWithoutPrefix()
{
$this->assertRegExp('/^([0-9]{9})|(\+351[0-9]{9})/', $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));
}
}