[Locale] fixed StubNumberFormatter::format() to behave like the NumberFormatter::parse() regarding to error flagging
This commit is contained in:
parent
f16ff892bb
commit
e4cbbf3e8c
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user