From e8cfd38f4d61368fb8500afb0b78ee5a344259f7 Mon Sep 17 00:00:00 2001 From: Thomas Moorhouse Date: Mon, 27 Mar 2017 18:12:13 +0100 Subject: [PATCH 1/6] Added UTF8 Emoji Generation to Miscellaneous Provider --- src/Faker/Provider/Miscellaneous.php | 32 +++++++++++++++++++++++ test/Faker/Provider/MiscellaneousTest.php | 5 ++++ 2 files changed, 37 insertions(+) diff --git a/src/Faker/Provider/Miscellaneous.php b/src/Faker/Provider/Miscellaneous.php index 4e051992fc..d04e171094 100644 --- a/src/Faker/Provider/Miscellaneous.php +++ b/src/Faker/Provider/Miscellaneous.php @@ -4,6 +4,28 @@ class Miscellaneous extends Base { + + /** + * @link https://en.wikipedia.org/wiki/Emoji#Unicode_blocks + * On date of 2017-03-26 + * + * U+1F600 - U+1F637 + */ + protected static $emoji = array( + "\u{1F600}", "\u{1F601}", "\u{1F602}", "\u{1F603}", "\u{1F604}", + "\u{1F605}", "\u{1F606}", "\u{1F607}", "\u{1F608}", "\u{1F609}", + "\u{1F60A}", "\u{1F60B}", "\u{1F60C}", "\u{1F60D}", "\u{1F60E}", + "\u{1F60F}", "\u{1F610}", "\u{1F611}", "\u{1F612}", "\u{1F613}", + "\u{1F614}", "\u{1F615}", "\u{1F616}", "\u{1F617}", "\u{1F618}", + "\u{1F619}", "\u{1F61A}", "\u{1F61B}", "\u{1F61C}", "\u{1F61D}", + "\u{1F61E}", "\u{1F61F}", "\u{1F620}", "\u{1F621}", "\u{1F622}", + "\u{1F623}", "\u{1F624}", "\u{1F625}", "\u{1F626}", "\u{1F627}", + "\u{1F628}", "\u{1F629}", "\u{1F62A}", "\u{1F62B}", "\u{1F62C}", + "\u{1F62D}", "\u{1F62E}", "\u{1F62F}", "\u{1F630}", "\u{1F631}", + "\u{1F632}", "\u{1F633}", "\u{1F634}", "\u{1F635}", "\u{1F636}", + "\u{1F637}" + ); + /** * @link https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes * On date of 2016-04-22 @@ -279,4 +301,14 @@ 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 static::randomElement(static::$emoji); + } } diff --git a/test/Faker/Provider/MiscellaneousTest.php b/test/Faker/Provider/MiscellaneousTest.php index 6a4c5591c0..c4938c3cf1 100644 --- a/test/Faker/Provider/MiscellaneousTest.php +++ b/test/Faker/Provider/MiscellaneousTest.php @@ -51,4 +51,9 @@ public function testCurrencyCode() { $this->assertRegExp('/^[A-Z]{3}$/', Miscellaneous::currencyCode()); } + + public function testEmoji() + { + $this->assertRegExp('/^[\x{1F600}-\x{1F636}]$/u', Miscellaneous::emoji()); + } } From c26949ed2ada3c148e4d8272ee25de16e871a927 Mon Sep 17 00:00:00 2001 From: Thomas Moorhouse Date: Mon, 27 Mar 2017 18:33:16 +0100 Subject: [PATCH 2/6] Made files PSR-2 compliant --- src/Faker/Provider/Miscellaneous.php | 16 ++++++++++------ test/Faker/Provider/MiscellaneousTest.php | 1 - 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Faker/Provider/Miscellaneous.php b/src/Faker/Provider/Miscellaneous.php index d04e171094..386de05c7d 100644 --- a/src/Faker/Provider/Miscellaneous.php +++ b/src/Faker/Provider/Miscellaneous.php @@ -4,7 +4,6 @@ class Miscellaneous extends Base { - /** * @link https://en.wikipedia.org/wiki/Emoji#Unicode_blocks * On date of 2017-03-26 @@ -23,7 +22,7 @@ class Miscellaneous extends Base "\u{1F628}", "\u{1F629}", "\u{1F62A}", "\u{1F62B}", "\u{1F62C}", "\u{1F62D}", "\u{1F62E}", "\u{1F62F}", "\u{1F630}", "\u{1F631}", "\u{1F632}", "\u{1F633}", "\u{1F634}", "\u{1F635}", "\u{1F636}", - "\u{1F637}" + "\u{1F637}", ); /** @@ -220,14 +219,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) @@ -269,6 +270,7 @@ public static function locale() /** * @example 'FR' + * * @link https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 */ public static function countryCode() @@ -278,6 +280,7 @@ public static function countryCode() /** * @example 'FRA' + * * @link https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 */ public static function countryISOAlpha3() @@ -295,6 +298,7 @@ public static function languageCode() /** * @example 'EUR' + * * @link https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 */ public static function currencyCode() @@ -303,7 +307,7 @@ public static function currencyCode() } /** - * Returns an encoded Unicode Character between U+1F600 and U+1F637 + * Returns an encoded Unicode Character between U+1F600 and U+1F637. * * @link https://en.wikipedia.org/wiki/Emoji#Unicode_blocks */ diff --git a/test/Faker/Provider/MiscellaneousTest.php b/test/Faker/Provider/MiscellaneousTest.php index c4938c3cf1..c0208e192d 100644 --- a/test/Faker/Provider/MiscellaneousTest.php +++ b/test/Faker/Provider/MiscellaneousTest.php @@ -6,7 +6,6 @@ class MiscellaneousTest extends \PHPUnit_Framework_TestCase { - public function testBoolean() { $this->assertContains(Miscellaneous::boolean(), array(true, false)); From 0a84ce9c754e4ef0c1a7980011e89be6ea5c49ba Mon Sep 17 00:00:00 2001 From: Thomas Moorhouse Date: Mon, 27 Mar 2017 18:44:49 +0100 Subject: [PATCH 3/6] Added example to readme --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index ff9aab514b..bace62e839 100644 --- a/readme.md +++ b/readme.md @@ -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` From 62b87b5de007df5dac40594df9258cbf397c4bbc Mon Sep 17 00:00:00 2001 From: Thomas Moorhouse Date: Mon, 27 Mar 2017 18:49:05 +0100 Subject: [PATCH 4/6] Changed readme example to actual unicode char --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index bace62e839..f72f89a49c 100644 --- a/readme.md +++ b/readme.md @@ -292,7 +292,7 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle countryCode // UK languageCode // en currencyCode // EUR - emoji // 😁 + emoji // 😁 ### `Faker\Provider\Biased` From 2fd6fe9f19ab9fbb262c9a03f50948767b097824 Mon Sep 17 00:00:00 2001 From: Thomas Moorhouse Date: Mon, 27 Mar 2017 20:07:15 +0100 Subject: [PATCH 5/6] Refactored to work with PHP 5 --- src/Faker/Provider/Miscellaneous.php | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Faker/Provider/Miscellaneous.php b/src/Faker/Provider/Miscellaneous.php index 386de05c7d..94773d4a0c 100644 --- a/src/Faker/Provider/Miscellaneous.php +++ b/src/Faker/Provider/Miscellaneous.php @@ -8,21 +8,23 @@ class Miscellaneous extends Base * @link https://en.wikipedia.org/wiki/Emoji#Unicode_blocks * On date of 2017-03-26 * - * U+1F600 - U+1F637 + * U+1F600 - U+1F637 as their UTF-8 Pairings */ protected static $emoji = array( - "\u{1F600}", "\u{1F601}", "\u{1F602}", "\u{1F603}", "\u{1F604}", - "\u{1F605}", "\u{1F606}", "\u{1F607}", "\u{1F608}", "\u{1F609}", - "\u{1F60A}", "\u{1F60B}", "\u{1F60C}", "\u{1F60D}", "\u{1F60E}", - "\u{1F60F}", "\u{1F610}", "\u{1F611}", "\u{1F612}", "\u{1F613}", - "\u{1F614}", "\u{1F615}", "\u{1F616}", "\u{1F617}", "\u{1F618}", - "\u{1F619}", "\u{1F61A}", "\u{1F61B}", "\u{1F61C}", "\u{1F61D}", - "\u{1F61E}", "\u{1F61F}", "\u{1F620}", "\u{1F621}", "\u{1F622}", - "\u{1F623}", "\u{1F624}", "\u{1F625}", "\u{1F626}", "\u{1F627}", - "\u{1F628}", "\u{1F629}", "\u{1F62A}", "\u{1F62B}", "\u{1F62C}", - "\u{1F62D}", "\u{1F62E}", "\u{1F62F}", "\u{1F630}", "\u{1F631}", - "\u{1F632}", "\u{1F633}", "\u{1F634}", "\u{1F635}", "\u{1F636}", - "\u{1F637}", + '\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', ); /** @@ -313,6 +315,6 @@ public static function currencyCode() */ public static function emoji() { - return static::randomElement(static::$emoji); + return json_decode('"' . static::randomElement(static::$emoji) . '"'); } } From bca3cbe7dbc8421d9892446294779a9d9314f851 Mon Sep 17 00:00:00 2001 From: Thomas Moorhouse Date: Mon, 27 Mar 2017 20:07:15 +0100 Subject: [PATCH 6/6] Refactored to work with PHP 5 --- src/Faker/Provider/Miscellaneous.php | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Faker/Provider/Miscellaneous.php b/src/Faker/Provider/Miscellaneous.php index 386de05c7d..94773d4a0c 100644 --- a/src/Faker/Provider/Miscellaneous.php +++ b/src/Faker/Provider/Miscellaneous.php @@ -8,21 +8,23 @@ class Miscellaneous extends Base * @link https://en.wikipedia.org/wiki/Emoji#Unicode_blocks * On date of 2017-03-26 * - * U+1F600 - U+1F637 + * U+1F600 - U+1F637 as their UTF-8 Pairings */ protected static $emoji = array( - "\u{1F600}", "\u{1F601}", "\u{1F602}", "\u{1F603}", "\u{1F604}", - "\u{1F605}", "\u{1F606}", "\u{1F607}", "\u{1F608}", "\u{1F609}", - "\u{1F60A}", "\u{1F60B}", "\u{1F60C}", "\u{1F60D}", "\u{1F60E}", - "\u{1F60F}", "\u{1F610}", "\u{1F611}", "\u{1F612}", "\u{1F613}", - "\u{1F614}", "\u{1F615}", "\u{1F616}", "\u{1F617}", "\u{1F618}", - "\u{1F619}", "\u{1F61A}", "\u{1F61B}", "\u{1F61C}", "\u{1F61D}", - "\u{1F61E}", "\u{1F61F}", "\u{1F620}", "\u{1F621}", "\u{1F622}", - "\u{1F623}", "\u{1F624}", "\u{1F625}", "\u{1F626}", "\u{1F627}", - "\u{1F628}", "\u{1F629}", "\u{1F62A}", "\u{1F62B}", "\u{1F62C}", - "\u{1F62D}", "\u{1F62E}", "\u{1F62F}", "\u{1F630}", "\u{1F631}", - "\u{1F632}", "\u{1F633}", "\u{1F634}", "\u{1F635}", "\u{1F636}", - "\u{1F637}", + '\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', ); /** @@ -313,6 +315,6 @@ public static function currencyCode() */ public static function emoji() { - return static::randomElement(static::$emoji); + return json_decode('"' . static::randomElement(static::$emoji) . '"'); } }