forked from fzaninotto/Faker
-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sri Lanka Provider Person and Phone Number #913
Open
avgkudey
wants to merge
2
commits into
FakerPHP:1.24
Choose a base branch
from
avgkudey:1.24
base: 1.24
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+264
−0
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
Sri Lanka Provider Person and Phone Number
commit 98004f26188c588706a416ec6cad735312ba2817
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
|
||
namespace Faker\Provider\en_SL; | ||
|
||
class Person extends \Faker\Provider\Person | ||
{ | ||
protected static $maleNameFormats = [ | ||
'{{firstNameMale}} {{lastName}}', | ||
'{{firstNameMale}} {{lastName}}', | ||
'{{firstNameMale}} {{lastName}}', | ||
'{{firstNameMale}} {{lastName}}', | ||
'{{titleMale}} {{firstNameMale}} {{lastName}}', | ||
'{{firstNameMale}} {{lastName}} {{suffix}}', | ||
'{{titleMale}} {{firstNameMale}} {{lastName}} {{suffix}}', | ||
]; | ||
|
||
protected static $femaleNameFormats = [ | ||
'{{firstNameFemale}} {{lastName}}', | ||
'{{firstNameFemale}} {{lastName}}', | ||
'{{firstNameFemale}} {{lastName}}', | ||
'{{firstNameFemale}} {{lastName}}', | ||
'{{titleFemale}} {{firstNameFemale}} {{lastName}}', | ||
'{{firstNameFemale}} {{lastName}} {{suffix}}', | ||
'{{titleFemale}} {{firstNameFemale}} {{lastName}} {{suffix}}', | ||
]; | ||
|
||
/** | ||
* Language Sinhala | ||
* Sri Lankan Male Names | ||
* | ||
* @see https://en.wikipedia.org/wiki/Category:Sinhalese_masculine_given_names | ||
*/ | ||
protected static $firstNameMale = [ | ||
'Abhaya', 'Adeesha', 'Ajit', 'Akila', 'Aloka', 'Amarasiri', 'Anura', 'Asanga', 'Buddhika', 'Chamara', 'Chandrasena', | ||
'Chandrasiri', 'Chathuranga', 'Dharmadasa', 'Dileesh', 'Dilshan', 'Dilum', 'Dinuk', 'Dishan', 'Edirisinghe', 'Elanga', | ||
'Gamini', 'Gehan', 'Gemunu', 'Hasaranga', 'Heen', 'Hemantha', 'Himesh', 'Imesh', 'Indunil', 'Iresh', 'Ishara', | ||
'Jagath', 'Janak', 'Janaka', 'Janith', 'Jayasekara', 'Jayaweera', 'Kalhara', 'Kanishka', 'Karunaratne', 'Kasun', | ||
'Kavinda', 'Kusal', 'Lahiru', 'Lakmal', 'Lakshan', 'Lalith', 'Lasantha', 'Maithripala', 'Mangala', 'Manjula', ' | ||
Mevan', 'Mohan', 'Nalaka', 'Nandasena', 'Nandasiri', 'Navod', 'Nimal', 'Niroshan', 'Nishantha', 'Nuwan', 'Palitha', | ||
'Prasanna', 'Priyantha', 'Ranil', 'Ranjith', 'Rashan', 'Raveen', 'Ravindu', 'Rohan', 'Romesh', 'Ruvin', 'Ruwan', | ||
'Sachith', 'Sajin', 'Sajith', 'Saliya', 'Samantha', 'Sanath', 'Sanjeeva', 'Sanjeewa', 'Shanaka', 'Shantha', | ||
'Shehan', 'Sujith', 'Supun', 'Suranjith', 'Tharindu', 'Thilan', 'Thiran', 'Thushara', 'Tissa', 'Udayanga', | ||
'Udesh', 'Upatissa', 'Upul', 'Vidura', 'Vijitha', 'Vimukthi', | ||
|
||
]; | ||
|
||
/** | ||
* @see https://en.wikipedia.org/wiki/Category:Sinhalese_feminine_given_names | ||
*/ | ||
protected static $firstNameFemale = [ | ||
'Abhisheka', 'Amanda', 'Amaya', 'Anuki', 'Anuradhi', 'Ashani', 'Ayesha', 'Chamari', 'Chathuri', | ||
'Dasuni', 'Devni', 'Dilani', 'Dilhani', 'Dineshi', 'Dhanushi', 'Dulanjani', 'Eshani', | ||
'Gayani', 'Gihani', 'Hansani', 'Hansini', 'Harshani', 'Heshani', 'Hiruni', 'Inoka', | ||
'Ishara', 'Janaki', 'Janani', 'Jayani', 'Kanchana', 'Kumari', 'Lakmini', 'Lakshika', | ||
'Malkanthi', 'Malithi', 'Manuri', 'Menaka', 'Nadeeshani', 'Nalini', 'Narmada', | ||
'Niranjana', 'Nimeshi', 'NIshani', 'Nishanthi', 'Nuwani', 'Pabodhi', 'Pavani', | ||
'Pramodi', 'Prasadi', 'Priyadarshani', 'Pravini', 'Ruwani', 'Rukshani', | ||
'Sachini', 'Sadani', 'Samadhi', 'Sanjeewani', 'Sarangi', 'Sewandi', | ||
'Shashikala', 'Sithumi', 'Subani', 'Sunethra', 'Surangi', 'Tharuki', | ||
'Tharushi', 'Thilani', 'Thilinka', 'Udeni', 'Umeshi', 'Upuli', 'Vasanthi', | ||
'Yashodara', | ||
]; | ||
|
||
/** | ||
* @see https://en.wikipedia.org/wiki/Category:Surnames_of_Sinhalese_origin | ||
*/ | ||
protected static $lastName = [ | ||
'Abayakoon', 'Abeygunawardena', 'Abeynaike', 'Abeyratne', 'Abeysekera', 'Abeysinghe', 'Abeywardena', | ||
'Abeywickrama', 'Adhikari', 'Adikaram', 'Ahangama', 'Aloka', 'Amarasiri', 'Amerasekera', 'Amerasinghe', | ||
'Anthonisz', 'Aponsu', 'Appuhamy', 'Arachchi', 'Attanayake', 'Attygalle', 'Atukorale', 'Balasuriya', 'Bandara', | ||
'Bandaranaike', 'Basnayake', 'Buddika', 'Chamara', 'Chandima', 'Chandrasena', 'Chandrasiri', 'Chathuranga', | ||
'Cooray', 'Coorey', 'Corea', 'Dahanayake', 'Daminda', 'Danushka', 'Dassanayake', 'De Abrew', 'De Alwis', | ||
'De Saram', 'Denipitiya', 'Deraniyagala', 'Devapriya', 'Dhammika', 'Dharmadasa', 'Dharmasena', 'Dilshan', | ||
'Disasekara', 'Dissanaike', 'Dissanayake', 'Dodangoda', 'Edirisinghe', 'Ekanayake', 'Fernando', 'Fonseka', | ||
'Gamage', 'Gunaratne', 'Gunasekera', 'Gunathilaka', 'Gunawardena', 'Hasaranga', 'Hathurusingha', 'Herath', | ||
'Indika', 'Indunil', 'Jayakody', 'Jayakumar', 'Jayaratne', 'Jayasekara', 'Jayasinghe', 'Jayasuriya', | ||
'Jayatilleka', 'Jayatissa', 'Jayaweera', 'Jayawickrama', 'Jayewardene', 'Kalhara', 'Kanchana', 'Karunadasa', | ||
'Karunaratne', 'Karunatilaka', 'Kasun', 'Kavinda', 'Kodikara', 'Kodithuwakku', 'Kulasekara', 'Kumarage', | ||
'Labrooy', 'Lakmal', 'Lakshitha', 'Liyanage', 'Madugalle', 'Madusanka', 'Madushan', 'Madushanka', 'Manjula', | ||
'Mendis', 'Munasinghe', 'Nanayakkara', 'Nandasena', 'Nandasiri', 'Niroshana', 'Opatha', 'Palihakkara', 'Pathirana', | ||
'Peiris', 'Perera', 'Prasanna', 'Premadasa', 'Premaratne', 'Priyadarshana', 'Rajapaksa', 'Rajasekara', 'Ramanayake', | ||
'Ranasinghe', 'Ranatunga', 'Ranawaka', 'Ranaweera', 'Ratnayake', 'Ratwatte', 'Rohana', 'Samarakoon', 'Samarasekera', | ||
'Samarasinghe', 'Samaraweera', 'Sandaruwan', 'Sanjeewa', 'Schokman', 'Senanayake', 'Senarath', 'Senasinghe', | ||
'Seneviratne', 'Shantha', 'Shehan', 'Sigera', 'Sirisena', 'Siriwardena', 'Subasinghe', 'Sudarshana', 'Sugathapala', | ||
'Tharanga', 'Thilakaratne', 'Thushara', 'Tissera', 'Udawatte', 'Udayanga', 'Vidura', 'Vimukthi', 'Warakagoda', | ||
'Weerakoon', 'Weeraratna', 'Weeraratne', 'Weerasekara', 'Weerasinghe', 'Weerasooriya', 'Weerawansa', 'Wickremasinghe', | ||
'Wijeratne', 'Wijesinghe', 'Wijesinha', 'Wijesuriya', 'Wijethunga', 'Wijetunga', 'Wijewardene', 'Wikramanayake', | ||
'Withanachchi', 'Yapa', | ||
]; | ||
|
||
protected static $suffix = ['Sr.', 'MD', 'DDS', 'PhD', 'DVM']; | ||
|
||
/** | ||
* @example 'PhD' | ||
*/ | ||
public static function suffix() | ||
{ | ||
return static::randomElement(static::$suffix); | ||
} | ||
|
||
/** | ||
* @example '901234567V' | ||
*/ | ||
public static function nicNumberOld() | ||
{ | ||
return sprintf( | ||
'%02d%02d%05d%s', | ||
self::numberBetween(0, 99), | ||
self::numberBetween(0, 99), | ||
self::numberBetween(1, 99999), | ||
self::randomElement(['V', 'X']), | ||
); | ||
} | ||
|
||
/** | ||
* @example '900123456789' | ||
*/ | ||
public static function nicNumber() | ||
{ | ||
return sprintf( | ||
'%s%04d%05d%02d', | ||
self::randomElement(['9', '0']), | ||
self::numberBetween(1900, 2024), | ||
self::numberBetween(1, 99999), | ||
self::numberBetween(0, 99), | ||
); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Faker\Provider\en_SL; | ||
|
||
class PhoneNumber extends \Faker\Provider\PhoneNumber | ||
{ | ||
protected static $mobileFormats = [ | ||
'+94 (071) ###-####', '+94 (072) ###-####', '+94 (074) ###-####', | ||
'+94 (075) ###-####', '+94 (076) ###-####', '+94 (077) ###-####', | ||
'+94 (078) ###-####', '+94 (079) ###-####', | ||
|
||
'(071) ###-####', '(072) ###-####', '(074) ###-####', | ||
'(075) ###-####', '(076) ###-####', '(077) ###-####', | ||
'(078) ###-####', '(079) ###-####', | ||
]; | ||
|
||
public static function mobileNumber() | ||
{ | ||
return static::numerify(static::randomElement(static::$mobileFormats)); | ||
} | ||
} |
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Faker\Test\Provider\en_SL; | ||
|
||
use Faker\Provider\en_SL\Person; | ||
use Faker\Test\TestCase; | ||
|
||
final class PersonTest extends TestCase | ||
{ | ||
public function testNicNumberOld(): void | ||
{ | ||
for ($i = 0; $i < 100; ++$i) { | ||
$nic = $this->faker->nicNumberOld; | ||
|
||
self::assertSame(10, strlen($nic)); | ||
self::assertMatchesRegularExpression('/^\d{9}[VX]$/', $nic); | ||
} | ||
} | ||
|
||
public function testMaleName(): void | ||
{ | ||
for ($i = 0; $i < 100; ++$i) { | ||
$name = $this->faker->name('male'); | ||
|
||
self::assertGreaterThan(0, strlen($name)); | ||
} | ||
} | ||
public function testFeMaleName(): void | ||
{ | ||
for ($i = 0; $i < 100; ++$i) { | ||
$name = $this->faker->name('female'); | ||
|
||
self::assertGreaterThan(0, strlen($name)); | ||
} | ||
} | ||
|
||
public function testNicNumber(): void | ||
{ | ||
for ($i = 0; $i < 100; ++$i) { | ||
$nic = $this->faker->nicNumber; | ||
|
||
self::assertSame(12, strlen($nic), "NIC number should be 12 characters long: $nic"); | ||
|
||
self::assertTrue(in_array($nic[0], ['9', '0'], true)); | ||
|
||
$year = (int) substr($nic, 1, 4); | ||
self::assertGreaterThanOrEqual(1900, $year); | ||
self::assertLessThanOrEqual((int) date('Y'), $year); | ||
|
||
$midPart = substr($nic, 5, 5); | ||
self::assertMatchesRegularExpression('/^\d{5}$/', $midPart); | ||
|
||
$lastPart = substr($nic, 10, 1); | ||
self::assertMatchesRegularExpression('/^\d$/', $lastPart); | ||
} | ||
} | ||
|
||
protected function getProviders(): iterable | ||
{ | ||
yield new Person($this->faker); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Faker\Test\Provider\en_SL; | ||
|
||
use Faker\Provider\en_SL\PhoneNumber; | ||
use Faker\Test\TestCase; | ||
|
||
final class PhoneNumberTest extends TestCase | ||
{ | ||
public function testMobileNumber(): void | ||
{ | ||
for ($i = 0; $i < 100; ++$i) { | ||
$number = $this->faker->mobileNumber; | ||
$digits = array_values(array_filter(str_split($number), 'ctype_digit')); | ||
|
||
// Check country code prefix for international format | ||
if (strpos($number, '+94') === 0) { | ||
$digits = array_slice($digits, 2); | ||
} | ||
// 10 digits total | ||
self::assertCount(10, $digits); | ||
|
||
// Check area codes (071-079) | ||
$areaCode = $digits[0] . $digits[1]; | ||
|
||
self::assertContains($areaCode, ['07', '07', '07', '07', '07', '07', '07', '07']); | ||
|
||
// Test format | ||
self::assertMatchesRegularExpression('/^(\+94)?([ -]*\(07\d\)[ -]*\d{3}[-]?\d{4})$/', $number); | ||
} | ||
} | ||
|
||
protected function getProviders(): iterable | ||
{ | ||
yield new PhoneNumber($this->faker); | ||
} | ||
} |
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.
Locale specific fields will not be included in the global generator
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.
Also for the others beneath this one