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

Commit

Permalink
Merge pull request #1175 from thomasfdm/master
Browse files Browse the repository at this point in the history
Added Emoji to Miscellaneous
  • Loading branch information
fzaninotto authored Mar 29, 2017
2 parents bb46053 + 9c25cf3 commit 0e3e900
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle
countryCode // UK
languageCode // en
currencyCode // EUR
emoji // 😁

### `Faker\Provider\Biased`

Expand Down
44 changes: 41 additions & 3 deletions src/Faker/Provider/Miscellaneous.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@

class Miscellaneous extends Base
{
/**
* @link https://en.wikipedia.org/wiki/Emoji#Unicode_blocks
* On date of 2017-03-26
*
* U+1F600 - U+1F637 as their UTF-8 Pairings
*/
protected static $emoji = array(
'\uD83D\uDE00', '\uD83D\uDE01', '\uD83D\uDE02', '\uD83D\uDE03',
'\uD83D\uDE04', '\uD83D\uDE05', '\uD83D\uDE06', '\uD83D\uDE07',
'\uD83D\uDE08', '\uD83D\uDE09', '\uD83D\uDE0A', '\uD83D\uDE0B',
'\uD83D\uDE0C', '\uD83D\uDE0D', '\uD83D\uDE0E', '\uD83D\uDE0F',
'\uD83D\uDE10', '\uD83D\uDE11', '\uD83D\uDE12', '\uD83D\uDE13',
'\uD83D\uDE14', '\uD83D\uDE15', '\uD83D\uDE16', '\uD83D\uDE17',
'\uD83D\uDE18', '\uD83D\uDE19', '\uD83D\uDE1A', '\uD83D\uDE1B',
'\uD83D\uDE1C', '\uD83D\uDE1D', '\uD83D\uDE1E', '\uD83D\uDE1F',
'\uD83D\uDE20', '\uD83D\uDE21', '\uD83D\uDE22', '\uD83D\uDE23',
'\uD83D\uDE24', '\uD83D\uDE25', '\uD83D\uDE26', '\uD83D\uDE27',
'\uD83D\uDE28', '\uD83D\uDE29', '\uD83D\uDE2A', '\uD83D\uDE2B',
'\uD83D\uDE2C', '\uD83D\uDE2D', '\uD83D\uDE2E', '\uD83D\uDE2F',
'\uD83D\uDE30', '\uD83D\uDE31', '\uD83D\uDE32', '\uD83D\uDE33',
'\uD83D\uDE34', '\uD83D\uDE35', '\uD83D\uDE36', '\uD83D\uDE37',
);

/**
* @link https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
* On date of 2016-04-22
Expand Down Expand Up @@ -198,14 +221,16 @@ class Miscellaneous extends Base
'SHP', 'SLL', 'SOS', 'SRD', 'STD', 'SVC', 'SYP', 'SZL', 'THB', 'TJS',
'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD',
'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XCD',
'XDR', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMK', 'ZMW', 'ZWL'
'XDR', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMK', 'ZMW', 'ZWL',
);

/**
* Return a boolean, true or false
* Return a boolean, true or false.
*
* @param int $chanceOfGettingTrue Between 0 (always get false) and 100 (always get true)
*
* @param integer $chanceOfGettingTrue Between 0 (always get false) and 100 (always get true).
* @return bool
*
* @example true
*/
public static function boolean($chanceOfGettingTrue = 50)
Expand Down Expand Up @@ -247,6 +272,7 @@ public static function locale()

/**
* @example 'FR'
*
* @link https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
*/
public static function countryCode()
Expand All @@ -256,6 +282,7 @@ public static function countryCode()

/**
* @example 'FRA'
*
* @link https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
*/
public static function countryISOAlpha3()
Expand All @@ -273,10 +300,21 @@ public static function languageCode()

/**
* @example 'EUR'
*
* @link https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
*/
public static function currencyCode()
{
return static::randomElement(static::$currencyCode);
}

/**
* Returns an encoded Unicode Character between U+1F600 and U+1F637.
*
* @link https://en.wikipedia.org/wiki/Emoji#Unicode_blocks
*/
public static function emoji()
{
return json_decode('"' . static::randomElement(static::$emoji) . '"');
}
}
6 changes: 5 additions & 1 deletion test/Faker/Provider/MiscellaneousTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class MiscellaneousTest extends \PHPUnit_Framework_TestCase
{

public function testBoolean()
{
$this->assertContains(Miscellaneous::boolean(), array(true, false));
Expand Down Expand Up @@ -51,4 +50,9 @@ public function testCurrencyCode()
{
$this->assertRegExp('/^[A-Z]{3}$/', Miscellaneous::currencyCode());
}

public function testEmoji()
{
$this->assertRegExp('/^[\x{1F600}-\x{1F636}]$/u', Miscellaneous::emoji());
}
}

0 comments on commit 0e3e900

Please sign in to comment.