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

Fix FR_fr 07 prefix mobile number generation #1343

Merged
merged 3 commits into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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++;
}
}
}