Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #782 from z38/swiss-phone-numbers
Browse files Browse the repository at this point in the history
Improve Swiss phone numbers
  • Loading branch information
fzaninotto committed Feb 23, 2016
2 parents 36e8938 + 88ced06 commit e150dea
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 36 deletions.
35 changes: 32 additions & 3 deletions src/Faker/Provider/de_CH/PhoneNumber.php
Expand Up @@ -5,10 +5,39 @@
class PhoneNumber extends \Faker\Provider\PhoneNumber
{
protected static $formats = array(
'+44 (0)## ### ## ##',
'+44(0)#########',
'+44 ## ### ## ##',
'+41 (0)## ### ## ##',
'+41(0)#########',
'+41 ## ### ## ##',
'0#########',
'0## ### ## ##',
);

/**
* An array of Swiss mobile (cell) phone number formats.
*
* @var array
*/
protected static $mobileFormats = array(
// Local
'075 ### ## ##',
'075#######',
'076 ### ## ##',
'076#######',
'077 ### ## ##',
'077#######',
'078 ### ## ##',
'078#######',
'079 ### ## ##',
'079#######',
);

/**
* Return a Swiss mobile phone number.
*
* @return string
*/
public static function mobileNumber()
{
return static::numerify(static::randomElement(static::$mobileFormats));
}
}
35 changes: 32 additions & 3 deletions src/Faker/Provider/fr_CH/PhoneNumber.php
Expand Up @@ -5,10 +5,39 @@
class PhoneNumber extends \Faker\Provider\PhoneNumber
{
protected static $formats = array(
'+44 (0)## ### ## ##',
'+44(0)#########',
'+44 ## ### ## ##',
'+41 (0)## ### ## ##',
'+41(0)#########',
'+41 ## ### ## ##',
'0#########',
'0## ### ## ##',
);

/**
* An array of Swiss mobile (cell) phone number formats.
*
* @var array
*/
protected static $mobileFormats = array(
// Local
'075 ### ## ##',
'075#######',
'076 ### ## ##',
'076#######',
'077 ### ## ##',
'077#######',
'078 ### ## ##',
'078#######',
'079 ### ## ##',
'079#######',
);

/**
* Return a Swiss mobile phone number.
*
* @return string
*/
public static function mobileNumber()
{
return static::numerify(static::randomElement(static::$mobileFormats));
}
}
35 changes: 32 additions & 3 deletions src/Faker/Provider/it_CH/PhoneNumber.php
Expand Up @@ -5,10 +5,39 @@
class PhoneNumber extends \Faker\Provider\PhoneNumber
{
protected static $formats = array(
'+44 (0)## ### ## ##',
'+44(0)#########',
'+44 ## ### ## ##',
'+41 (0)## ### ## ##',
'+41(0)#########',
'+41 ## ### ## ##',
'0#########',
'0## ### ## ##',
);

/**
* An array of Swiss mobile (cell) phone number formats.
*
* @var array
*/
protected static $mobileFormats = array(
// Local
'075 ### ## ##',
'075#######',
'076 ### ## ##',
'076#######',
'077 ### ## ##',
'077#######',
'078 ### ## ##',
'078#######',
'079 ### ## ##',
'079#######',
);

/**
* Return a Swiss mobile phone number.
*
* @return string
*/
public static function mobileNumber()
{
return static::numerify(static::randomElement(static::$mobileFormats));
}
}
14 changes: 5 additions & 9 deletions test/Faker/Provider/de_CH/PhoneNumberTest.php
Expand Up @@ -20,17 +20,13 @@ public function setUp()
$this->faker = $faker;
}

/**
* @test
* @dataProvider phoneNumberFormatProvider
*/
public function phoneNumberFormat()
public function testPhoneNumber()
{
$number = $this->faker->phoneNumber;
$this->assertRegExp('/^0\d{2} ?\d{3} ?\d{2} ?\d{2}|\+44 ?(\(0\))?\d{2} ?\d{3} ?\d{2} ?\d{2}$/', $number);
$this->assertRegExp('/^0\d{2} ?\d{3} ?\d{2} ?\d{2}|\+41 ?(\(0\))?\d{2} ?\d{3} ?\d{2} ?\d{2}$/', $this->faker->phoneNumber());
}

public function phoneNumberFormatProvider (){
return array(array(), array(), array(), array(), array(), array(), array(), array(), array(), array());
public function testMobileNumber()
{
$this->assertRegExp('/^07[56789] ?\d{3} ?\d{2} ?\d{2}$/', $this->faker->mobileNumber());
}
}
14 changes: 5 additions & 9 deletions test/Faker/Provider/fr_CH/PhoneNumberTest.php
Expand Up @@ -20,17 +20,13 @@ public function setUp()
$this->faker = $faker;
}

/**
* @test
* @dataProvider phoneNumberFormatProvider
*/
public function phoneNumberFormat()
public function testPhoneNumber()
{
$number = $this->faker->phoneNumber;
$this->assertRegExp('/^0\d{2} ?\d{3} ?\d{2} ?\d{2}|\+44 ?(\(0\))?\d{2} ?\d{3} ?\d{2} ?\d{2}$/', $number);
$this->assertRegExp('/^0\d{2} ?\d{3} ?\d{2} ?\d{2}|\+41 ?(\(0\))?\d{2} ?\d{3} ?\d{2} ?\d{2}$/', $this->faker->phoneNumber());
}

public function phoneNumberFormatProvider (){
return array(array(), array(), array(), array(), array(), array(), array(), array(), array(), array());
public function testMobileNumber()
{
$this->assertRegExp('/^07[56789] ?\d{3} ?\d{2} ?\d{2}$/', $this->faker->mobileNumber());
}
}
14 changes: 5 additions & 9 deletions test/Faker/Provider/it_CH/PhoneNumberTest.php
Expand Up @@ -20,17 +20,13 @@ public function setUp()
$this->faker = $faker;
}

/**
* @test
* @dataProvider phoneNumberFormatProvider
*/
public function phoneNumberFormat()
public function testPhoneNumber()
{
$number = $this->faker->phoneNumber;
$this->assertRegExp('/^0\d{2} ?\d{3} ?\d{2} ?\d{2}|\+44 ?(\(0\))?\d{2} ?\d{3} ?\d{2} ?\d{2}$/', $number);
$this->assertRegExp('/^0\d{2} ?\d{3} ?\d{2} ?\d{2}|\+41 ?(\(0\))?\d{2} ?\d{3} ?\d{2} ?\d{2}$/', $this->faker->phoneNumber());
}

public function phoneNumberFormatProvider (){
return array(array(), array(), array(), array(), array(), array(), array(), array(), array(), array());
public function testMobileNumber()
{
$this->assertRegExp('/^07[56789] ?\d{3} ?\d{2} ?\d{2}$/', $this->faker->mobileNumber());
}
}

0 comments on commit e150dea

Please sign in to comment.