diff --git a/readme.md b/readme.md index 48978389fe..c25c36de39 100644 --- a/readme.md +++ b/readme.md @@ -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 +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 diff --git a/src/Faker/Provider/fr_FR/PhoneNumber.php b/src/Faker/Provider/fr_FR/PhoneNumber.php index d0287fbcf8..7c0bd9d5e9 100644 --- a/src/Faker/Provider/fr_FR/PhoneNumber.php +++ b/src/Faker/Provider/fr_FR/PhoneNumber.php @@ -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 ## ## ## ##', @@ -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########', @@ -35,7 +35,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber '05########', '06########', '07{{phoneNumber07}}', - '08########', + '08{{phoneNumber08}}', '09########', '01 ## ## ## ##', '01 ## ## ## ##', @@ -45,7 +45,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber '05 ## ## ## ##', '06 ## ## ## ##', '07 {{phoneNumber07WithSeparator}}', - '08 ## ## ## ##', + '08 {{phoneNumber08WithSeparator}}', '09 ## ## ## ##', ); @@ -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(); @@ -81,6 +88,38 @@ 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' */ @@ -88,6 +127,15 @@ 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)); } } diff --git a/test/Faker/Provider/fr_FR/PhoneNumberTest.php b/test/Faker/Provider/fr_FR/PhoneNumberTest.php index d35098d8b9..d4179709b8 100644 --- a/test/Faker/Provider/fr_FR/PhoneNumberTest.php +++ b/test/Faker/Provider/fr_FR/PhoneNumberTest.php @@ -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); } }