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 #1343 from svanpoeck/master
Browse files Browse the repository at this point in the history
Fix FR_fr 07 prefix mobile number generation
  • Loading branch information
fzaninotto authored Nov 30, 2017
2 parents 01e31fa + 4e75c77 commit 724b08f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Faker/Provider/fr_FR/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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));
}
}
61 changes: 61 additions & 0 deletions test/Faker/Provider/fr_FR/PhoneNumberTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Faker\Test\Provider\fr_FR;

use Faker\Generator;
use Faker\Provider\fr_FR\PhoneNumber;

class PhoneNumberTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Generator
*/
private $faker;

public function setUp()
{
$faker = new Generator();
$faker->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++;
}
}
}

0 comments on commit 724b08f

Please sign in to comment.