4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Intl\Tests\NumberFormatter
;
14 use Symfony\Component\Intl\Globals\IntlGlobals
;
15 use Symfony\Component\Intl\NumberFormatter\NumberFormatter
;
16 use Symfony\Component\Intl\Util\IntlTestHelper
;
19 * Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known
22 class NumberFormatterTest
extends AbstractNumberFormatterTest
24 protected function setUp()
26 IntlTestHelper
::requireIntl($this);
32 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
34 public function testConstructorWithUnsupportedLocale()
36 new NumberFormatter('pt_BR');
40 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
42 public function testConstructorWithUnsupportedStyle()
44 new NumberFormatter('en', NumberFormatter
::PATTERN_DECIMAL
);
48 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentNotImplementedException
50 public function testConstructorWithPatternDifferentThanNull()
52 new NumberFormatter('en', NumberFormatter
::DECIMAL
, '');
56 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
58 public function testSetAttributeWithUnsupportedAttribute()
60 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
61 $formatter->setAttribute(NumberFormatter
::LENIENT_PARSE
, null);
65 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
67 public function testSetAttributeInvalidRoundingMode()
69 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
70 $formatter->setAttribute(NumberFormatter
::ROUNDING_MODE
, null);
73 public function testCreate()
75 $this->assertInstanceOf(
76 '\Symfony\Component\Intl\NumberFormatter\NumberFormatter',
77 NumberFormatter
::create('en', NumberFormatter
::DECIMAL
)
82 * @expectedException \RuntimeException
84 public function testFormatWithCurrencyStyle()
86 parent
::testFormatWithCurrencyStyle();
90 * @dataProvider formatTypeInt32Provider
91 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
93 public function testFormatTypeInt32($formatter, $value, $expected, $message = '')
95 parent
::testFormatTypeInt32($formatter, $value, $expected, $message);
99 * @dataProvider formatTypeInt32WithCurrencyStyleProvider
100 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
102 public function testFormatTypeInt32WithCurrencyStyle($formatter, $value, $expected, $message = '')
104 parent
::testFormatTypeInt32WithCurrencyStyle($formatter, $value, $expected, $message);
108 * @dataProvider formatTypeInt64Provider
109 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
111 public function testFormatTypeInt64($formatter, $value, $expected)
113 parent
::testFormatTypeInt64($formatter, $value, $expected);
117 * @dataProvider formatTypeInt64WithCurrencyStyleProvider
118 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
120 public function testFormatTypeInt64WithCurrencyStyle($formatter, $value, $expected)
122 parent
::testFormatTypeInt64WithCurrencyStyle($formatter, $value, $expected);
126 * @dataProvider formatTypeDoubleProvider
127 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
129 public function testFormatTypeDouble($formatter, $value, $expected)
131 parent
::testFormatTypeDouble($formatter, $value, $expected);
135 * @dataProvider formatTypeDoubleWithCurrencyStyleProvider
136 * @expectedException \Symfony\Component\Intl\Exception\NotImplementedException
138 public function testFormatTypeDoubleWithCurrencyStyle($formatter, $value, $expected)
140 parent
::testFormatTypeDoubleWithCurrencyStyle($formatter, $value, $expected);
144 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
146 public function testGetPattern()
148 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
149 $formatter->getPattern();
153 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
155 public function testGetSymbol()
157 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
158 $formatter->getSymbol(null);
162 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
164 public function testGetTextAttribute()
166 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
167 $formatter->getTextAttribute(null);
170 public function testGetErrorCode()
172 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
173 $this->assertEquals(IntlGlobals
::U_ZERO_ERROR
, $formatter->getErrorCode());
177 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
179 public function testParseCurrency()
181 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
182 $formatter->parseCurrency(null, $currency);
186 * @expectedException \Symfony\Component\Intl\Exception\MethodArgumentNotImplementedException
188 public function testParseWithNotNullPositionValue()
190 parent
::testParseWithNotNullPositionValue();
194 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
196 public function testSetPattern()
198 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
199 $formatter->setPattern(null);
203 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
205 public function testSetSymbol()
207 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
208 $formatter->setSymbol(null, null);
212 * @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
214 public function testSetTextAttribute()
216 $formatter = $this->getNumberFormatter('en', NumberFormatter
::DECIMAL
);
217 $formatter->setTextAttribute(null, null);
220 protected function getNumberFormatter($locale = 'en', $style = null, $pattern = null)
222 return new NumberFormatter($locale, $style, $pattern);
225 protected function getIntlErrorMessage()
227 return IntlGlobals
::getErrorMessage();
230 protected function getIntlErrorCode()
232 return IntlGlobals
::getErrorCode();
235 protected function isIntlFailure($errorCode)
237 return IntlGlobals
::isFailure($errorCode);