Skip to content

Commit

Permalink
Use PHPUnit 9.6 to run Symfony's test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Feb 15, 2023
1 parent af0e32d commit afc5628
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions Tests/NumberFormatter/AbstractNumberFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Intl\Tests\NumberFormatter;

use PHPUnit\Framework\Error\Warning;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Globals\IntlGlobals;
use Symfony\Component\Intl\NumberFormatter\NumberFormatter;
Expand Down Expand Up @@ -328,13 +327,17 @@ public function testFormatTypeCurrency($formatter, $value)
{
if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
} elseif (method_exists($this, 'expectWarning')) {
$this->expectWarning();
} else {
$this->expectException(Warning::class);
$this->expectException(\ErrorException::class);
}

$formatter->format($value, NumberFormatter::TYPE_CURRENCY);
set_error_handler([self::class, 'throwOnWarning']);

try {
$formatter->format($value, NumberFormatter::TYPE_CURRENCY);
} finally {
restore_error_handler();
}
}

/**
Expand Down Expand Up @@ -705,16 +708,21 @@ public static function parseProvider()

public function testParseTypeDefault()
{
$formatter = static::getNumberFormatter('en', NumberFormatter::DECIMAL);

if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
} elseif (method_exists($this, 'expectWarning')) {
$this->expectWarning();
} else {
$this->expectException(Warning::class);
$this->expectException(\ErrorException::class);
}

$formatter = static::getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->parse('1', NumberFormatter::TYPE_DEFAULT);
set_error_handler([self::class, 'throwOnWarning']);

try {
$formatter->parse('1', NumberFormatter::TYPE_DEFAULT);
} finally {
restore_error_handler();
}
}

/**
Expand Down Expand Up @@ -831,16 +839,21 @@ public static function parseTypeDoubleProvider()

public function testParseTypeCurrency()
{
$formatter = static::getNumberFormatter('en', NumberFormatter::DECIMAL);

if (\PHP_VERSION_ID >= 80000) {
$this->expectException(\ValueError::class);
} elseif (method_exists($this, 'expectWarning')) {
$this->expectWarning();
} else {
$this->expectException(Warning::class);
$this->expectException(\ErrorException::class);
}

$formatter = static::getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->parse('1', NumberFormatter::TYPE_CURRENCY);
set_error_handler([self::class, 'throwOnWarning']);

try {
$formatter->parse('1', NumberFormatter::TYPE_CURRENCY);
} finally {
restore_error_handler();
}
}

public function testParseWithNotNullPositionValue()
Expand All @@ -864,4 +877,13 @@ abstract protected function getIntlErrorCode(): int;
* @param int $errorCode
*/
abstract protected function isIntlFailure($errorCode): bool;

public static function throwOnWarning(int $errno, string $errstr, string $errfile = null, int $errline = null): bool
{
if ($errno & (\E_WARNING | \E_USER_WARNING)) {
throw new \ErrorException($errstr, 0, $errno, $errfile ?? __FILE__, $errline ?? __LINE__);
}

return false;
}
}

0 comments on commit afc5628

Please sign in to comment.