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