Merge branch '3.4' into 4.4

* 3.4:
  [Intl] promote warnings to value errors on PHP 8
  Fix CS
  DateTime validator support for trailing data
This commit is contained in:
Christian Flothmann 2020-09-09 10:00:22 +02:00
commit 0ed20be407
4 changed files with 35 additions and 3 deletions

View File

@ -357,6 +357,10 @@ abstract class NumberFormatter
// The original NumberFormatter does not support this format type
if (self::TYPE_CURRENCY === $type) {
if (\PHP_VERSION_ID >= 80000) {
throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%s given).', $type));
}
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
return false;
@ -513,6 +517,10 @@ abstract class NumberFormatter
$type = (int) $type;
if (self::TYPE_DEFAULT === $type || self::TYPE_CURRENCY === $type) {
if (\PHP_VERSION_ID >= 80000) {
throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%d given).', $type));
}
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
return false;

View File

@ -324,7 +324,9 @@ abstract class AbstractNumberFormatterTest extends TestCase
*/
public function testFormatTypeCurrency($formatter, $value)
{
if (method_exists($this, 'expectWarning')) {
if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
} elseif (method_exists($this, 'expectWarning')) {
$this->expectWarning();
} else {
$this->expectException(Warning::class);
@ -338,6 +340,10 @@ abstract class AbstractNumberFormatterTest extends TestCase
*/
public function testFormatTypeCurrencyReturn($formatter, $value)
{
if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
}
$this->assertFalse(@$formatter->format($value, NumberFormatter::TYPE_CURRENCY));
}
@ -709,7 +715,9 @@ abstract class AbstractNumberFormatterTest extends TestCase
public function testParseTypeDefault()
{
if (method_exists($this, 'expectWarning')) {
if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
} elseif (method_exists($this, 'expectWarning')) {
$this->expectWarning();
} else {
$this->expectException(Warning::class);
@ -833,7 +841,9 @@ abstract class AbstractNumberFormatterTest extends TestCase
public function testParseTypeCurrency()
{
if (method_exists($this, 'expectWarning')) {
if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
} elseif (method_exists($this, 'expectWarning')) {
$this->expectWarning();
} else {
$this->expectException(Warning::class);

View File

@ -59,6 +59,12 @@ class DateTimeValidator extends DateValidator
return;
}
if ('+' === substr($constraint->format, -1)) {
$errors['warnings'] = array_filter($errors['warnings'], function ($warning) {
return 'Trailing data' !== $warning;
});
}
foreach ($errors['warnings'] as $warning) {
if ('The parsed date was invalid' === $warning) {
$this->context->buildViolation($constraint->message)

View File

@ -136,4 +136,12 @@ class DateTimeValidatorTest extends ConstraintValidatorTestCase
['Y-m-d H:i:s', '2010-01-01 00:00:60', DateTime::INVALID_TIME_ERROR],
];
}
public function testDateTimeWithTrailingData()
{
$this->validator->validate('1995-05-10 00:00:00', new DateTime([
'format' => 'Y-m-d+',
]));
$this->assertNoViolation();
}
}