From 6f9c05d4f9824298f8e608d093f1512b8c8ac9d4 Mon Sep 17 00:00:00 2001 From: stealth35 Date: Mon, 16 Apr 2012 13:30:41 +0200 Subject: [PATCH 1/2] [Locale] Complete Stub with intl_error_name --- .../Locale/Resources/stubs/functions.php | 11 +++++ .../Component/Locale/Stub/StubIntl.php | 14 ++++++ .../Component/Locale/Stub/StubIntlTest.php | 47 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php diff --git a/src/Symfony/Component/Locale/Resources/stubs/functions.php b/src/Symfony/Component/Locale/Resources/stubs/functions.php index 100f6fb99d..2444c3735a 100644 --- a/src/Symfony/Component/Locale/Resources/stubs/functions.php +++ b/src/Symfony/Component/Locale/Resources/stubs/functions.php @@ -45,3 +45,14 @@ function intl_get_error_code() { function intl_get_error_message() { return StubIntl::getErrorMessage(); } + +/** + * Stub implementation for the intl_error_name function of the intl extension + * + * @return String will be the same as the name of the error code constant + * + * @see Symfony\Component\Locale\Stub\StubIntl::getErrorName + */ +function intl_error_name($errorCode) { + return StubIntl::getErrorName($errorCode); +} \ No newline at end of file diff --git a/src/Symfony/Component/Locale/Stub/StubIntl.php b/src/Symfony/Component/Locale/Stub/StubIntl.php index 1dfc731884..8c8648027b 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntl.php +++ b/src/Symfony/Component/Locale/Stub/StubIntl.php @@ -101,6 +101,20 @@ abstract class StubIntl return self::$errorMessage; } + /** + * Returns the symbolic name for a given error code + * + * @return string + */ + static public function getErrorName($code) + { + if (isset(self::$errorCodes[$code])) { + return self::$errorCodes[$code]; + } + + return '[BOGUS UErrorCode]'; + } + /** * Sets the current error * diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php new file mode 100644 index 0000000000..b26eb46a0b --- /dev/null +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\Locale\Stub; + +require_once __DIR__.'/../TestCase.php'; + +use Symfony\Component\Locale\Locale; +use Symfony\Component\Locale\Stub\StubIntl; +use Symfony\Tests\Component\Locale\TestCase as LocaleTestCase; + +class StubIntlTest extends LocaleTestCase +{ + public function codeProvider() + { + return array ( + array(0, 'U_ZERO_ERROR'), + array(1, 'U_ILLEGAL_ARGUMENT_ERROR'), + array(9, 'U_PARSE_ERROR'), + ); + } + + /** + * @dataProvider codeProvider + */ + public function testGetErrorName($code, $name) + { + $this->assertSame($name, StubIntl::getErrorName($code)); + } + + /** + * @dataProvider codeProvider + */ + public function testGetErrorNameWithIntl($code, $name) + { + $this->skipIfIntlExtensionIsNotLoaded(); + $this->assertSame(intl_error_name($code), StubIntl::getErrorName($code)); + } +} From 5799d2532468ac6d58bcf6ac3f9b2cc18556d6e6 Mon Sep 17 00:00:00 2001 From: stealth35 Date: Mon, 16 Apr 2012 13:33:13 +0200 Subject: [PATCH 2/2] Add BOGUS UErrorCode test --- tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php index b26eb46a0b..a8c8e07094 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php @@ -22,9 +22,11 @@ class StubIntlTest extends LocaleTestCase public function codeProvider() { return array ( + array(-129, '[BOGUS UErrorCode]'), array(0, 'U_ZERO_ERROR'), array(1, 'U_ILLEGAL_ARGUMENT_ERROR'), array(9, 'U_PARSE_ERROR'), + array(129, '[BOGUS UErrorCode]'), ); }