This repository has been archived by the owner on Dec 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
US phone numbers #615
Merged
Merged
US phone numbers #615
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b5d5622
Added parse to phone formats
okj579 9abb9bd
Added phone number formatter for en_US
okj579 dd5de62
Update readme.md
okj579 9579460
Moved randomDigitNot to Base Provider, Added unit test
okj579 1f657d0
Added PhoneNumber::tollFreeAreaCode()
okj579 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Faker\Test\Provider\en_US; | ||
|
||
use Faker\Generator; | ||
use Faker\Provider\en_US\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 testPhoneNumber() | ||
{ | ||
for ($i = 0; $i < 100; $i++) { | ||
$number = $this->faker->phoneNumber; | ||
$baseNumber = preg_replace('/ *x.*$/', '', $number); // Remove possible extension | ||
$digits = array_values(array_filter(str_split($baseNumber), 'ctype_digit')); | ||
|
||
// Prefix '1' allowed | ||
if (count($digits) === 11) { | ||
$this->assertEquals('1', $digits[0]); | ||
$digits = array_slice($digits, 1); | ||
} | ||
|
||
// 10 digits | ||
$this->assertEquals(10, count($digits)); | ||
|
||
// Last two digits of area code cannot be identical | ||
$this->assertNotEquals($digits[1], $digits[2]); | ||
|
||
// Last two digits of exchange code cannot be 1 | ||
if ($digits[4] === 1) { | ||
$this->assertNotEquals($digits[4], $digits[5]); | ||
} | ||
|
||
// Test format | ||
$this->assertRegExp('/^(\+?1)?([ -.]*\d{3}[ -.]*| *\(\d{3}\) *)\d{3}[-.]?\d{4}$/', $baseNumber); | ||
} | ||
} | ||
|
||
public function testTollFreeAreaCode() | ||
{ | ||
$this->assertContains($this->faker->tollFreeAreaCode, array(800, 822, 833, 844, 855, 866, 877, 888, 880, 887, 889)); | ||
} | ||
|
||
public function testTollFreePhoneNumber() | ||
{ | ||
for ($i = 0; $i < 100; $i++) { | ||
$number = $this->faker->tollFreePhoneNumber; | ||
$digits = array_values(array_filter(str_split($number), 'ctype_digit')); | ||
|
||
// Prefix '1' allowed | ||
if (count($digits) === 11) { | ||
$this->assertEquals('1', $digits[0]); | ||
$digits = array_slice($digits, 1); | ||
} | ||
|
||
// 10 digits | ||
$this->assertEquals(10, count($digits)); | ||
|
||
$areaCode = $digits[0] . $digits[1] . $digits[2]; | ||
$this->assertContains($areaCode, array('800', '822', '833', '844', '855', '866', '877', '888', '880', '887', '889')); | ||
|
||
// Last two digits of exchange code cannot be 1 | ||
if ($digits[4] === 1) { | ||
$this->assertNotEquals($digits[4], $digits[5]); | ||
} | ||
|
||
// Test format | ||
$this->assertRegExp('/^(\+?1)?([ -.]*\d{3}[ -.]*| *\(\d{3}\) *)\d{3}[-.]?\d{4}$/', $number); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break many locales overriding this method with a
static
one. If you change it here, you must change it in locales, too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I just saw that you actually did that further down in the PR ;)