1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Polyfill\Tests\Intl\Icu;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Polyfill\Intl\Icu\Exception\MethodArgumentNotImplementedException;
use Symfony\Polyfill\Intl\Icu\Exception\MethodArgumentValueNotImplementedException;
use Symfony\Polyfill\Intl\Icu\Exception\MethodNotImplementedException;
use Symfony\Polyfill\Intl\Icu\Exception\NotImplementedException;
use Symfony\Polyfill\Intl\Icu\Icu;
use Symfony\Polyfill\Intl\Icu\NumberFormatter;
/**
* Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known
* behavior of PHP.
*
* @group class-polyfill
*/
class NumberFormatterTest extends AbstractNumberFormatterTestCase
{
public function testConstructorWithUnsupportedLocale()
{
$this->expectException(MethodArgumentValueNotImplementedException::class);
self::getNumberFormatter('pt_BR');
}
public function testConstructorWithUnsupportedStyle()
{
$this->expectException(MethodArgumentValueNotImplementedException::class);
self::getNumberFormatter('en', NumberFormatter::PATTERN_DECIMAL);
}
public function testConstructorWithPatternDifferentThanNull()
{
$this->expectException(MethodArgumentNotImplementedException::class);
self::getNumberFormatter('en', NumberFormatter::DECIMAL, '');
}
public function testSetAttributeWithUnsupportedAttribute()
{
$this->expectException(MethodArgumentValueNotImplementedException::class);
$formatter = self::getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::LENIENT_PARSE, 100);
}
public function testSetAttributeInvalidRoundingMode()
{
$this->expectException(MethodArgumentValueNotImplementedException::class);
$formatter = self::getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, -1);
}
public function testConstructWithoutLocale()
{
$this->assertInstanceOf(NumberFormatter::class, self::getNumberFormatter(null, NumberFormatter::DECIMAL));
}
public function testCreate()
{
$formatter = self::getNumberFormatter('en', NumberFormatter::DECIMAL);
$this->assertInstanceOf(NumberFormatter::class, $formatter::create('en', NumberFormatter::DECIMAL));
}
public function testFormatWithCurrencyStyle()
{
$this->expectException('RuntimeException');
parent::testFormatWithCurrencyStyle();
}
/**
* @dataProvider formatTypeInt32Provider */
#[DataProvider('formatTypeInt32Provider')]
public function testFormatTypeInt32($formatter, $value, $expected, $message = '')
{
$this->expectException(MethodArgumentValueNotImplementedException::class);
parent::testFormatTypeInt32($formatter, $value, $expected, $message);
}
/**
* @dataProvider formatTypeInt32WithCurrencyStyleProvider
*/
#[DataProvider('formatTypeInt32WithCurrencyStyleProvider')]
public function testFormatTypeInt32WithCurrencyStyle($formatter, $value, $expected, $message = '')
{
$this->expectException(NotImplementedException::class);
parent::testFormatTypeInt32WithCurrencyStyle($formatter, $value, $expected, $message);
}
/**
* @dataProvider formatTypeInt64Provider
*/
#[DataProvider('formatTypeInt64Provider')]
public function testFormatTypeInt64($formatter, $value, $expected)
{
$this->expectException(MethodArgumentValueNotImplementedException::class);
parent::testFormatTypeInt64($formatter, $value, $expected);
}
/**
* @dataProvider formatTypeInt64WithCurrencyStyleProvider
*/
#[DataProvider('formatTypeInt64WithCurrencyStyleProvider')]
public function testFormatTypeInt64WithCurrencyStyle($formatter, $value, $expected)
{
$this->expectException(NotImplementedException::class);
parent::testFormatTypeInt64WithCurrencyStyle($formatter, $value, $expected);
}
/**
* @dataProvider formatTypeDoubleProvider
*/
#[DataProvider('formatTypeDoubleProvider')]
public function testFormatTypeDouble($formatter, $value, $expected)
{
$this->expectException(MethodArgumentValueNotImplementedException::class);
parent::testFormatTypeDouble($formatter, $value, $expected);
}
/**
* @dataProvider formatTypeDoubleWithCurrencyStyleProvider
*/
#[DataProvider('formatTypeDoubleWithCurrencyStyleProvider')]
public function testFormatTypeDoubleWithCurrencyStyle($formatter, $value, $expected)
{
$this->expectException(NotImplementedException::class);
parent::testFormatTypeDoubleWithCurrencyStyle($formatter, $value, $expected);
}
public function testGetPattern()
{
$this->expectException(MethodNotImplementedException::class);
$formatter = self::getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->getPattern();
}
public function testGetErrorCode()
{
$formatter = self::getNumberFormatter('en', NumberFormatter::DECIMAL);
$this->assertEquals(Icu::U_ZERO_ERROR, $formatter->getErrorCode());
}
public function testParseCurrency()
{
$this->expectException(MethodNotImplementedException::class);
$formatter = self::getNumberFormatter('en', NumberFormatter::DECIMAL);
$currency = 'USD';
$formatter->parseCurrency(3, $currency);
}
public function testSetPattern()
{
$this->expectException(MethodNotImplementedException::class);
$formatter = self::getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setPattern('#0');
}
public function testSetSymbol()
{
$this->expectException(MethodNotImplementedException::class);
$formatter = self::getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '*');
}
public function testSetTextAttribute()
{
$this->expectException(MethodNotImplementedException::class);
$formatter = self::getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, '-');
}
protected static function getNumberFormatter(?string $locale = 'en', ?string $style = null, ?string $pattern = null): NumberFormatter
{
return new class($locale, $style, $pattern) extends NumberFormatter {
};
}
protected static function getIntlErrorMessage(): string
{
return Icu::getErrorMessage();
}
protected static function getIntlErrorCode(): int
{
return Icu::getErrorCode();
}
protected static function isIntlFailure($errorCode): bool
{
return Icu::isFailure($errorCode);
}
}
|