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

Adds valid 08 number formats for fr_FR #1439

Merged
merged 4 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
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
40 changes: 36 additions & 4 deletions src/Faker/Provider/fr_FR/PhoneNumber.php
Original file line number Diff line number Diff line change
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,6 +88,24 @@ public function phoneNumber07WithSeparator()
return $phoneNumber;
}

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

/**
*
* @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}';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please document it better to it's easier to modify in the future if the rules change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the formats as documentation, the missing 4|6 numbers aren't attributed yet.

return $this->regexify($regex);
}

/**
* @example '0601020304'
*/
Expand All @@ -90,4 +115,11 @@ public function mobileNumber()

return static::numerify($this->generator->parse($format));
}

public function serviceNumber()
{
$format = static::randomElement(static::$serviceFormats);

return static::numerify($this->generator->parse($format));
}
}
20 changes: 20 additions & 0 deletions test/Faker/Provider/fr_FR/PhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,24 @@ public function testMobileNumber07WithSeparator()
$i++;
}
}

public function testServiceNumber()
{
do {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if you tested phoneNumber08WithSeparator instead, that would avoid doing the loop

$service = $this->faker->serviceNumber();
} while (' ' == $service[2] || '08' != substr($service, 0, 2));
$this->assertRegExp('/^08((0|1|2)\d{1}|9[^46])\d{6}$/', $service);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give a reference for this regular expression

}

public function testServiceNumberWithSeparator()
{
$i = 0;
while (10 > $i) {
do {
$service = $this->faker->serviceNumber();
} while ('+33 8' != substr($service, 0, 5));
$this->assertRegExp('/^\+33 8 ((0|1|2)\d{1}|9[^46])( \d{2}){3}$/', $service);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, please test an inner function instead of looping until you get the right format

$i++;
}
}
}