diff --git a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php index a3a0412094..c4949d062c 100644 --- a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php @@ -351,8 +351,14 @@ class StubNumberFormatter $fractionDigits = $this->getAttribute(self::FRACTION_DIGITS); $value = $this->round($value, $fractionDigits); + $value = $this->formatNumber($value, $fractionDigits); - return $this->formatNumber($value, $fractionDigits); + // behave like the intl extension + StubIntl::setError(StubIntl::U_ZERO_ERROR); + $this->errorCode = StubIntl::getErrorCode(); + $this->errorMessage = StubIntl::getErrorMessage(); + + return $value; } /** diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php index 000d736af7..1236598ab7 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php @@ -225,15 +225,36 @@ class StubNumberFormatterTest extends LocaleTestCase public function testFormatStub() { + $errorCode = StubIntl::U_ZERO_ERROR; + $errorMessage = 'U_ZERO_ERROR'; + $formatter = $this->getStubFormatterWithDecimalStyle(); $this->assertSame('9.555', $formatter->format(9.555)); + + $this->assertSame($errorMessage, StubIntl::getErrorMessage()); + $this->assertSame($errorCode, StubIntl::getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode())); + $this->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); } public function testFormatIntl() { $this->skipIfIntlExtensionIsNotLoaded(); + + $errorCode = StubIntl::U_ZERO_ERROR; + $errorMessage = 'U_ZERO_ERROR'; + $formatter = $this->getIntlFormatterWithDecimalStyle(); $this->assertSame('9.555', $formatter->format(9.555)); + + $this->assertSame($errorMessage, intl_get_error_message()); + $this->assertSame($errorCode, intl_get_error_code()); + $this->assertSame($errorCode != 0, intl_is_failure(intl_get_error_code())); + $this->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, intl_is_failure($formatter->getErrorCode())); } /**