Skip to content

Commit 0ed20be

Browse files
committed
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
2 parents bb3bc7f + 81b954b commit 0ed20be

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ public function format($value, $type = self::TYPE_DEFAULT)
357357

358358
// The original NumberFormatter does not support this format type
359359
if (self::TYPE_CURRENCY === $type) {
360+
if (\PHP_VERSION_ID >= 80000) {
361+
throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%s given).', $type));
362+
}
363+
360364
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
361365

362366
return false;
@@ -513,6 +517,10 @@ public function parse($value, $type = self::TYPE_DOUBLE, &$position = 0)
513517
$type = (int) $type;
514518

515519
if (self::TYPE_DEFAULT === $type || self::TYPE_CURRENCY === $type) {
520+
if (\PHP_VERSION_ID >= 80000) {
521+
throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%d given).', $type));
522+
}
523+
516524
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
517525

518526
return false;

src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ public function formatTypeDoubleWithCurrencyStyleProvider()
324324
*/
325325
public function testFormatTypeCurrency($formatter, $value)
326326
{
327-
if (method_exists($this, 'expectWarning')) {
327+
if (\PHP_VERSION_ID >= 80000) {
328+
$this->expectException(\ValueError::class);
329+
} elseif (method_exists($this, 'expectWarning')) {
328330
$this->expectWarning();
329331
} else {
330332
$this->expectException(Warning::class);
@@ -338,6 +340,10 @@ public function testFormatTypeCurrency($formatter, $value)
338340
*/
339341
public function testFormatTypeCurrencyReturn($formatter, $value)
340342
{
343+
if (\PHP_VERSION_ID >= 80000) {
344+
$this->expectException(\ValueError::class);
345+
}
346+
341347
$this->assertFalse(@$formatter->format($value, NumberFormatter::TYPE_CURRENCY));
342348
}
343349

@@ -709,7 +715,9 @@ public function parseProvider()
709715

710716
public function testParseTypeDefault()
711717
{
712-
if (method_exists($this, 'expectWarning')) {
718+
if (\PHP_VERSION_ID >= 80000) {
719+
$this->expectException(\ValueError::class);
720+
} elseif (method_exists($this, 'expectWarning')) {
713721
$this->expectWarning();
714722
} else {
715723
$this->expectException(Warning::class);
@@ -833,7 +841,9 @@ public function parseTypeDoubleProvider()
833841

834842
public function testParseTypeCurrency()
835843
{
836-
if (method_exists($this, 'expectWarning')) {
844+
if (\PHP_VERSION_ID >= 80000) {
845+
$this->expectException(\ValueError::class);
846+
} elseif (method_exists($this, 'expectWarning')) {
837847
$this->expectWarning();
838848
} else {
839849
$this->expectException(Warning::class);

src/Symfony/Component/Validator/Constraints/DateTimeValidator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public function validate($value, Constraint $constraint)
5959
return;
6060
}
6161

62+
if ('+' === substr($constraint->format, -1)) {
63+
$errors['warnings'] = array_filter($errors['warnings'], function ($warning) {
64+
return 'Trailing data' !== $warning;
65+
});
66+
}
67+
6268
foreach ($errors['warnings'] as $warning) {
6369
if ('The parsed date was invalid' === $warning) {
6470
$this->context->buildViolation($constraint->message)

src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,12 @@ public function getInvalidDateTimes()
136136
['Y-m-d H:i:s', '2010-01-01 00:00:60', DateTime::INVALID_TIME_ERROR],
137137
];
138138
}
139+
140+
public function testDateTimeWithTrailingData()
141+
{
142+
$this->validator->validate('1995-05-10 00:00:00', new DateTime([
143+
'format' => 'Y-m-d+',
144+
]));
145+
$this->assertNoViolation();
146+
}
139147
}

0 commit comments

Comments
 (0)