[Locale] fixed StubNumberFormatter::parse() to behave like the NumberFormatter::parse() regarding to error flagging
This commit is contained in:
parent
0a606642b7
commit
f16ff892bb
@ -501,7 +501,7 @@ class StubNumberFormatter
|
|||||||
|
|
||||||
// Any string before the numeric value causes error in the parsing
|
// Any string before the numeric value causes error in the parsing
|
||||||
if (isset($matches[1]) && !empty($matches[1])) {
|
if (isset($matches[1]) && !empty($matches[1])) {
|
||||||
StubIntl::setError(StubIntl::U_PARSE_ERROR);
|
StubIntl::setError(StubIntl::U_PARSE_ERROR, 'Number parsing failed');
|
||||||
$this->errorCode = StubIntl::getErrorCode();
|
$this->errorCode = StubIntl::getErrorCode();
|
||||||
$this->errorMessage = StubIntl::getErrorMessage();
|
$this->errorMessage = StubIntl::getErrorMessage();
|
||||||
|
|
||||||
@ -510,8 +510,14 @@ class StubNumberFormatter
|
|||||||
|
|
||||||
// Remove everything that is not number or dot (.)
|
// Remove everything that is not number or dot (.)
|
||||||
$value = preg_replace('/[^0-9\.\-]/', '', $value);
|
$value = preg_replace('/[^0-9\.\-]/', '', $value);
|
||||||
|
$value = $this->convertValueDataType($value, $type);
|
||||||
|
|
||||||
return $this->convertValueDataType($value, $type);
|
// behave like the intl extension
|
||||||
|
StubIntl::setError(StubIntl::U_ZERO_ERROR);
|
||||||
|
$this->errorCode = StubIntl::getErrorCode();
|
||||||
|
$this->errorMessage = StubIntl::getErrorMessage();
|
||||||
|
|
||||||
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -669,10 +669,19 @@ class StubNumberFormatterTest extends LocaleTestCase
|
|||||||
$this->assertSame($expected, $parsedValue, $message);
|
$this->assertSame($expected, $parsedValue, $message);
|
||||||
|
|
||||||
if ($expected === false) {
|
if ($expected === false) {
|
||||||
$this->assertSame(StubIntl::U_PARSE_ERROR, $formatter->getErrorCode());
|
$errorCode = StubIntl::U_PARSE_ERROR;
|
||||||
|
$errorMessage = 'Number parsing failed: U_PARSE_ERROR';
|
||||||
} else {
|
} else {
|
||||||
$this->assertEquals(StubIntl::U_ZERO_ERROR, $formatter->getErrorCode());
|
$errorCode = StubIntl::U_ZERO_ERROR;
|
||||||
|
$errorMessage = 'U_ZERO_ERROR';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -682,15 +691,25 @@ class StubNumberFormatterTest extends LocaleTestCase
|
|||||||
{
|
{
|
||||||
$this->skipIfIntlExtensionIsNotLoaded();
|
$this->skipIfIntlExtensionIsNotLoaded();
|
||||||
$this->skipIfICUVersionIsTooOld();
|
$this->skipIfICUVersionIsTooOld();
|
||||||
|
|
||||||
$formatter = $this->getIntlFormatterWithDecimalStyle();
|
$formatter = $this->getIntlFormatterWithDecimalStyle();
|
||||||
$parsedValue = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE);
|
$parsedValue = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE);
|
||||||
$this->assertSame($expected, $parsedValue, $message);
|
$this->assertSame($expected, $parsedValue, $message);
|
||||||
|
|
||||||
if ($expected === false) {
|
if ($expected === false) {
|
||||||
$this->assertSame(U_PARSE_ERROR, $formatter->getErrorCode());
|
$errorCode = StubIntl::U_PARSE_ERROR;
|
||||||
|
$errorMessage = 'Number parsing failed: U_PARSE_ERROR';
|
||||||
} else {
|
} else {
|
||||||
$this->assertEquals(U_ZERO_ERROR, $formatter->getErrorCode());
|
$errorCode = StubIntl::U_ZERO_ERROR;
|
||||||
|
$errorMessage = 'U_ZERO_ERROR';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseProvider()
|
public function parseProvider()
|
||||||
|
Reference in New Issue
Block a user