From 82d9d41d573f10dae058f88318e6759b22dedd01 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 9 Sep 2020 09:04:38 +0200 Subject: [PATCH] [Intl] promote warnings to value errors on PHP 8 --- .../Intl/NumberFormatter/NumberFormatter.php | 8 ++++++++ .../AbstractNumberFormatterTest.php | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index 72a110bf2a..579681ee6a 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -357,6 +357,10 @@ 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 @@ 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; diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php index dd6a300c55..9cc628911b 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php @@ -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);