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 #1439 from ppelgrims/fix-french-phone-numbers
Browse files Browse the repository at this point in the history
Adds valid 08 number formats for fr_FR
  • Loading branch information
fzaninotto committed Jun 13, 2018
2 parents fd7cf3b + 85d28b7 commit 587b0ab
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 32 deletions.
12 changes: 12 additions & 0 deletions readme.md
Expand Up @@ -1137,6 +1137,18 @@ echo $faker->vat; // FR 12 123 456 789
echo $faker->nir; // 1 88 07 35 127 571 - 19
```

### `Faker\Provider\fr_FR\PhoneNumber`

```php
<?php

// Generates phone numbers
echo $faker->phoneNumber; // +33 (0)1 67 97 01 31
echo $faker->mobileNumber; // +33 6 21 12 72 84
echo $faker->serviceNumber // 08 98 04 84 46
```


### `Faker\Provider\he_IL\Payment`

```php
Expand Down
56 changes: 52 additions & 4 deletions src/Faker/Provider/fr_FR/PhoneNumber.php
Expand Up @@ -15,7 +15,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'+33 (0)5 ## ## ## ##',
'+33 (0)6 ## ## ## ##',
'+33 (0)7 {{phoneNumber07WithSeparator}}',
'+33 (0)8 ## ## ## ##',
'+33 (0)8 {{phoneNumber08WithSeparator}}',
'+33 (0)9 ## ## ## ##',
'+33 1 ## ## ## ##',
'+33 1 ## ## ## ##',
Expand All @@ -25,7 +25,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'+33 5 ## ## ## ##',
'+33 6 ## ## ## ##',
'+33 7 {{phoneNumber07WithSeparator}}',
'+33 8 ## ## ## ##',
'+33 8 {{phoneNumber08WithSeparator}}',
'+33 9 ## ## ## ##',
'01########',
'01########',
Expand All @@ -35,7 +35,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'05########',
'06########',
'07{{phoneNumber07}}',
'08########',
'08{{phoneNumber08}}',
'09########',
'01 ## ## ## ##',
'01 ## ## ## ##',
Expand All @@ -45,7 +45,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'05 ## ## ## ##',
'06 ## ## ## ##',
'07 {{phoneNumber07WithSeparator}}',
'08 ## ## ## ##',
'08 {{phoneNumber08WithSeparator}}',
'09 ## ## ## ##',
);

Expand All @@ -62,6 +62,13 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'07 {{phoneNumber07WithSeparator}}',
);

protected static $serviceFormats = array(
'+33 (0)8 {{phoneNumber08WithSeparator}}',
'+33 8 {{phoneNumber08WithSeparator}}',
'08 {{phoneNumber08WithSeparator}}',
'08{{phoneNumber08}}',
);

public function phoneNumber07()
{
$phoneNumber = $this->phoneNumber07WithSeparator();
Expand All @@ -81,13 +88,54 @@ public function phoneNumber07WithSeparator()
return $phoneNumber;
}

public function phoneNumber08()
{
$phoneNumber = $this->phoneNumber08WithSeparator();
$phoneNumber = str_replace(' ', '', $phoneNumber);
return $phoneNumber;
}

/**
* Valid formats for 08:
*
* 0# ## ## ##
* 1# ## ## ##
* 2# ## ## ##
* 91 ## ## ##
* 92 ## ## ##
* 93 ## ## ##
* 97 ## ## ##
* 98 ## ## ##
* 99 ## ## ##
*
* Formats 089(4|6)## ## ## are valid, but will be
* attributed when other 089 resource ranges are exhausted.
*
* @see https://www.arcep.fr/index.php?id=8146#c9625
* @see https://issuetracker.google.com/u/1/issues/73269839
*/
public function phoneNumber08WithSeparator()
{
$regex = '([012]{1}\d{1}|(9[1-357-9])( \d{2}){3}';
return $this->regexify($regex);
}

/**
* @example '0601020304'
*/
public function mobileNumber()
{
$format = static::randomElement(static::$mobileFormats);

return static::numerify($this->generator->parse($format));
}
/**
* @example '0891951357'
*/
public function serviceNumber()
{
$format = static::randomElement(static::$serviceFormats);

return static::numerify($this->generator->parse($format));
}
}
52 changes: 24 additions & 28 deletions test/Faker/Provider/fr_FR/PhoneNumberTest.php
Expand Up @@ -19,43 +19,39 @@ public function setUp()
$this->faker = $faker;
}

public function testMobileNumber06()
public function testMobileNumber()
{
do {
$mobile = $this->faker->mobileNumber();
} while (' ' == $mobile[2] || '06' != substr($mobile, 0, 2));
$this->assertRegExp('/^06(?:\d{2}){4}$/', $mobile);
$mobileNumber = $this->faker->mobileNumber();
$this->assertRegExp('/^(\+33 |\+33 \(0\)|0)(6|7)(?:(\s{1})?\d{2}){4}$/', $mobileNumber);
}

public function testMobileNumber06WithSeparator()
public function testMobileNumber07Format()
{
$i = 0;
while (10 > $i) {
do {
$mobile = $this->faker->mobileNumber();
} while ('+33 6' != substr($mobile, 0, 5) && '06 ' != substr($mobile, 0, 3));
$this->assertRegExp('/^(?:(?:\+33 (?:\(0\))?)|0)6(?: \d{2}){4}$/', $mobile);
$i++;
}
$mobileNumberFormat = $this->faker->phoneNumber07();
$this->assertRegExp('/^([3-9]{1})\d(\d{2}){3}$/', $mobileNumberFormat);
}

public function testMobileNumber07()
public function testMobileNumber07WithSeparatorFormat()
{
do {
$mobile = $this->faker->mobileNumber();
} while (' ' == $mobile[2] || '07' != substr($mobile, 0, 2));
$this->assertRegExp('/^07(?:3|4|5|6|7|8|9)\d(?:\d{2}){3}$/', $mobile);
$mobileNumberFormat = $this->faker->phoneNumber07WithSeparator();
$this->assertRegExp('/^([3-9]{1})\d( \d{2}){3}$/', $mobileNumberFormat);
}

public function testMobileNumber07WithSeparator()
public function testServiceNumber()
{
$i = 0;
while (10 > $i) {
do {
$mobile = $this->faker->mobileNumber();
} while ('+33 7' != substr($mobile, 0, 5));
$this->assertRegExp('/^(?:(?:\+33 (?:\(0\))?)|0)7 (?:3|4|5|6|7|8|9)\d(?: \d{2}){3}$/', $mobile);
$i++;
}
$serviceNumber = $this->faker->serviceNumber();
$this->assertRegExp('/^(\+33 |\+33 \(0\)|0)8(?:(\s{1})?\d{2}){4}$/', $serviceNumber);
}

public function testServiceNumberFormat()
{
$serviceNumberFormat = $this->faker->phoneNumber08();
$this->assertRegExp('/^((0|1|2)\d{1}|9[^46])\d{6}$/', $serviceNumberFormat);
}

public function testServiceNumberWithSeparatorFormat()
{
$serviceNumberFormat = $this->faker->phoneNumber08WithSeparator();
$this->assertRegExp('/^((0|1|2)\d{1}|9[^46])( \d{2}){3}$/', $serviceNumberFormat);
}
}

0 comments on commit 587b0ab

Please sign in to comment.