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

Commit 63644ac

Browse files
zimingpimjansen
authored andcommitted
Bug Fix en_SG mobile number generation (#1658)
* Fix SG mobile number generation * rename function to oneToEight * Fix en_SG mobile test regex * fix en_SG mobile regex test 2
1 parent b618562 commit 63644ac

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/Faker/Provider/en_SG/PhoneNumber.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
1111

1212
protected static $zeroToEight = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
1313

14-
protected static $oneToNine = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
14+
protected static $oneToEight = array(1, 2, 3, 4, 5, 6, 7, 8);
1515

1616
protected static $mobileNumberFormats = array(
1717
'{{internationalCodePrefix}}9{{zeroToEight}}## ####',
1818
'{{internationalCodePrefix}} 9{{zeroToEight}}## ####',
1919
'9{{zeroToEight}}## ####',
20-
'{{internationalCodePrefix}}8{{oneToNine}}## ####',
21-
'{{internationalCodePrefix}} 8{{oneToNine}}## ####',
22-
'8{{oneToNine}}## ####',
23-
'{{internationalCodePrefix}}7{{oneToNine}}## ####',
24-
'{{internationalCodePrefix}} 7{{oneToNine}}## ####',
25-
'7{{oneToNine}}## ####',
20+
'{{internationalCodePrefix}}8{{oneToEight}}## ####',
21+
'{{internationalCodePrefix}} 8{{oneToEight}}## ####',
22+
'8{{oneToEight}}## ####',
2623
);
2724

2825
protected static $fixedLineNumberFormats = array(
@@ -103,8 +100,8 @@ public function zeroToEight()
103100
return static::randomElement(static::$zeroToEight);
104101
}
105102

106-
public function oneToNine()
103+
public function oneToEight()
107104
{
108-
return static::randomElement(static::$oneToNine);
105+
return static::randomElement(static::$oneToEight);
109106
}
110107
}

test/Faker/Provider/en_SG/PhoneNumberTest.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public function setUp()
1818
}
1919

2020
// http://en.wikipedia.org/wiki/Telephone_numbers_in_Singapore#Numbering_plan
21-
// y means 0 to 8 only
2221
// x means 0 to 9
22+
// y means 0 to 8 only
2323
public function testMobilePhoneNumberStartWith9Returns9yxxxxxx()
2424
{
2525
$startsWith9 = false;
@@ -28,19 +28,19 @@ public function testMobilePhoneNumberStartWith9Returns9yxxxxxx()
2828
$startsWith9 = preg_match('/^(\+65|65)?\s*9/', $mobileNumber);
2929
}
3030

31-
$this->assertRegExp('/^(\+65|65)?\s*9\s*[0-8]{3}\s*\d{4}$/', $mobileNumber);
31+
$this->assertRegExp('/^(\+65|65)?\s*9\s*[0-8]\d{2}\s*\d{4}$/', $mobileNumber);
3232
}
3333

3434
// http://en.wikipedia.org/wiki/Telephone_numbers_in_Singapore#Numbering_plan
35-
// z means 1 to 9 only
3635
// x means 0 to 9
37-
public function testMobilePhoneNumberStartWith7Or8Returns7Or8zxxxxxx()
36+
// z means 1 to 8 only
37+
public function testMobilePhoneNumberStartWith8Returns8zxxxxxx()
3838
{
39-
$startsWith7Or8 = false;
40-
while (!$startsWith7Or8) {
39+
$startsWith8 = false;
40+
while (!$startsWith8) {
4141
$mobileNumber = $this->faker->mobileNumber();
42-
$startsWith7Or8 = preg_match('/^(\+65|65)?\s*[7-8]/', $mobileNumber);
42+
$startsWith8 = preg_match('/^(\+65|65)?\s*8/', $mobileNumber);
4343
}
44-
$this->assertRegExp('/^(\+65|65)?\s*[7-8]\s*[1-9]{3}\s*\d{4}$/', $mobileNumber);
44+
$this->assertRegExp('/^(\+65|65)?\s*8\s*[1-8]\d{2}\s*\d{4}$/', $mobileNumber);
4545
}
4646
}

0 commit comments

Comments
 (0)