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

added Country ISO 3166-1 alpha-3 code #422

Merged
merged 2 commits into from
Sep 23, 2014
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
10 changes: 10 additions & 0 deletions src/Faker/Provider/Miscellaneous.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Miscellaneous extends \Faker\Provider\Base

protected static $countryCode = array('CA', 'CN', 'DE', 'ES', 'FR', 'IE', 'IN', 'IT', 'MX', 'PT', 'RU', 'GB', 'US');

protected static $countryISOAlpha3 = array('CAN', 'CHN', 'DEU', 'ESP', 'FRA', 'IRL', 'IND', 'ITA', 'MEX', 'PRT', 'RUS', 'GBR', 'USA');
Copy link
Owner

Choose a reason for hiding this comment

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

In fact, if we are to add more country formatters, I suggest you populate the array of possibilities with ALL the existing country codes (and do the same for $countryCode). At the moment, there is no reason to let a country in or out this data, so let's put them all in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I added all official ISO 3166 country codes


protected static $localeData = array(
'aa_DJ', 'aa_ER', 'aa_ET',
'af_NA', 'af_ZA', 'ak_GH',
Expand Down Expand Up @@ -142,6 +144,14 @@ public static function countryCode()
return static::randomElement(static::$countryCode);
}

/**
* @example 'FRA'
Copy link
Owner

Choose a reason for hiding this comment

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

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 link to the source

*/
public static function countryISOAlpha3()
{
return static::randomElement(static::$countryISOAlpha3);
}

/**
* @example 'fr'
*/
Expand Down
5 changes: 5 additions & 0 deletions test/Faker/Provider/MiscellaneousTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public function testCountryCode()
$this->assertRegExp('/^[A-Z]{2}$/', Miscellaneous::countryCode());
}

public function testCountryISOAlpha3()
{
$this->assertRegExp('/^[A-Z]{3}$/', Miscellaneous::countryISOAlpha3());
}

public function testLanguage()
{
$this->assertRegExp('/^[a-z]{2}$/', Miscellaneous::languageCode());
Expand Down