diff --git a/src/Faker/Provider/fr_FR/PhoneNumber.php b/src/Faker/Provider/fr_FR/PhoneNumber.php index 52736050ce..d0287fbcf8 100644 --- a/src/Faker/Provider/fr_FR/PhoneNumber.php +++ b/src/Faker/Provider/fr_FR/PhoneNumber.php @@ -52,12 +52,14 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber // Mobile phone numbers start by 06 and 07 // 06 is the most common prefix protected static $mobileFormats = array( + '+33 (0)6 ## ## ## ##', '+33 6 ## ## ## ##', + '+33 (0)7 {{phoneNumber07WithSeparator}}', '+33 7 {{phoneNumber07WithSeparator}}', '06########', - '07########', + '07{{phoneNumber07}}', '06 ## ## ## ##', - '07 ## ## ## ##', + '07 {{phoneNumber07WithSeparator}}', ); public function phoneNumber07() @@ -82,8 +84,10 @@ public function phoneNumber07WithSeparator() /** * @example '0601020304' */ - public static function mobileNumber() + public function mobileNumber() { - return static::numerify(static::randomElement(static::$mobileFormats)); + $format = static::randomElement(static::$mobileFormats); + + 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 new file mode 100644 index 0000000000..d35098d8b9 --- /dev/null +++ b/test/Faker/Provider/fr_FR/PhoneNumberTest.php @@ -0,0 +1,61 @@ +addProvider(new PhoneNumber($faker)); + $this->faker = $faker; + } + + public function testMobileNumber06() + { + do { + $mobile = $this->faker->mobileNumber(); + } while (' ' == $mobile[2] || '06' != substr($mobile, 0, 2)); + $this->assertRegExp('/^06(?:\d{2}){4}$/', $mobile); + } + + public function testMobileNumber06WithSeparator() + { + $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++; + } + } + + public function testMobileNumber07() + { + 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); + } + + public function testMobileNumber07WithSeparator() + { + $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++; + } + } +}