8000 [Locale] fixed tests · symfony/symfony@5fe58bf · GitHub
[go: up one dir, main page]

Skip to content

Commit 5fe58bf

Browse files
committed
[Locale] fixed tests
1 parent 500cc3c commit 5fe58bf

File tree

5 files changed

+81
-42
lines changed

5 files changed

+81
-42
lines changed

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
syntaxCheck="false"
1212
bootstrap="tests/bootstrap.php"
1313
>
14+
<php>
15+
<ini name="intl.default_locale" value="en"/>
16+
<ini name="intl.error_level" value="0"/>
17+
</php>
1418
<testsuites>
1519
<testsuite name="Symfony Test Suite">
1620
<directory>./tests/Symfony/</directory>

tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ public function testTransformLongTime()
9191
{
9292
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::LONG);
9393

94-
$this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime));
94+
$expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT';
95+
96+
$this->assertEquals($expected, $transformer->transform($this->dateTime));
9597
}
9698

9799
public function testTransformFullTime()
@@ -102,7 +104,9 @@ public function testTransformFullTime()
102104

103105
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL);
104106

105-
$this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime));
107+
$expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT';
108+
109+
$this->assertEquals($expected, $transformer->transform($this->dateTime));
106110
}
107111

108112
public function testTransformToDifferentLocale()

tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,8 @@ public function formatProvider()
123123
$formatData = array(
124124
/* general */
125125
array('y-M-d', 0, '1970-1-1'),
126-
array("yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 GMT+00:00'),
127126
array("EEE, MMM d, ''yy", 0, "Thu, Jan 1, '70"),
128127
array('h:mm a', 0, '12:00 AM'),
129-
array('K:mm a, z', 0, '0:00 AM, GMT+00:00'),
130128
array('yyyyy.MMMM.dd hh:mm aaa', 0, '01970.January.01 12:00 AM'),
131129

132130
/* escaping */
@@ -287,26 +285,36 @@ public function formatProvider()
287285
array('s', 3601, '1'),
288286
array('s', 3630, '30'),
289287
array('s', 43200, '0'), // 12 hours
290-
291-
/* timezone */
292-
array('z', 0, 'GMT+00:00'),
293-
array('zz', 0, 'GMT+00:00'),
294-
array('zzz', 0, 'GMT+00:00'),
295-
array('zzzz', 0, 'GMT+00:00'),
296-
array('zzzzz', 0, 'GMT+00:00'),
297288
);
298289

290+
// Timezone
291+
if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) {
292+
// general
293+
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 GMT+00:00');
294+
$formatData[] = array('K:mm a, z', 0, '0:00 AM, GMT+00:00');
295+
296+
// timezone
297+
$formatData[] = array('z', 0, 'GMT+00:00');
298+
$formatData[] = array('zz', 0, 'GMT+00:00');
299+
$formatData[] = array('zzz', 0, 'GMT+00:00');
300+
$formatData[] = array('zzzz', 0, 'GMT+00:00');
301+
$formatData[] = array('zzzzz', 0, 'GMT+00:00');
302+
}
303+
299304
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
300305
if ($this->isGreaterOrEqualThanPhpVersion('5.3.4')) {
301306
$dateTime = new \DateTime('@0');
302307

303308
/* general, DateTime */
304309
$formatData[] = array('y-M-d', $dateTime, '1970-1-1');
305-
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00');
306310
$formatData[] = array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70");
307311
$formatData[] = array('h:mm a', $dateTime, '12:00 AM');
308-
$formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00');
309312
$formatData[] = array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM');
313+
314+
if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) {
315+
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00');
316+
$formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00');
317+
}
310318
}
311319

312320
return $formatData;
@@ -430,7 +438,9 @@ public function testFormatWithTimezoneFormatOptionAndDifferentThanUtcIntl()
430438
$this->skipIfIntlExtensionIsNotLoaded();
431439
$formatter = $this->createIntlFormatter('zzzz');
432440
$formatter->setTimeZoneId('Pacific/Fiji');
433-
$this->assertEquals('Fiji Time', $formatter->format(0));
441+
442+
$expected = $this->isGreaterOrEqualThanIcuVersion('49') ? 'Fiji Standard Time' : 'Fiji Time';
443+
$this->assertEquals($expected, $formatter->format(0));
434444
}
435445

436446
public function testFormatWithGmtTimezoneStub()
@@ -464,7 +474,7 @@ public function testFormatWithDefaultTimezoneIntl()
464474
$this->skipIfIntlExtensionIsNotLoaded();
465475
$this->skipIfICUVersionIsTooOld();
466476

467-
$formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT);
477+
$formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC');
468478
$formatter->setPattern('yyyy-MM-dd HH:mm:ss');
469479

470480
$this->assertEquals(
@@ -493,7 +503,7 @@ public function testFormatWithDefaultTimezoneStubShouldUseTheTzEnvironmentVariab
493503
}
494504

495505
/**
496-
* It seems IntlDateFormatter caches the timezone id when not explicitely set via constructor or by the
506+
* It seems IntlDateFormatter caches the timezone id when not explicitly set via constructor or by the
497507
* setTimeZoneId() method. Since testFormatWithDefaultTimezoneIntl() runs using the default environment
498508
* time zone, this test would use it too if not running in a separated process.
499509
*
@@ -561,17 +571,21 @@ public function testDateAndTimeTypeIntl($timestamp, $datetype, $timetype, $expec
561571

562572
public function dateAndTimeTypeProvider()
563573
{
564-
return array(
574+
$data = array(
565575
array(0, StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, 'Thursday, January 1, 1970'),
566576
array(0, StubIntlDateFormatter::LONG, StubIntlDateFormatter::NONE, 'January 1, 1970'),
567577
array(0, StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::NONE, 'Jan 1, 1970'),
568578
array(0, StubIntlDateFormatter::SHORT, StubIntlDateFormatter::NONE, '1/1/70'),
569-
570-
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT+00:00'),
571-
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT+00:00'),
572579
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::MEDIUM, '12:00:00 AM'),
573580
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::SHORT, '12:00 AM'),
574581
);
582+
583+
if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) {
584+
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT+00:00');
585+
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT+00:00');
586+
}
587+
588+
return $data;
575589
}
576590

577591
public function testGetCalendar()
@@ -847,10 +861,7 @@ public function testParseErrorStub($pattern, $value)
847861

848862
public function parseErrorProvider()
849863
{
850-
return array(
851-
array('y-M-d', '1970/1/1'),
852-
array('yy-M-d', '70/1/1'),
853-
864+
$data = array(
854865
// 1 char month
855866
array('y-MMMMM-d', '1970-J-1'),
856867
array('y-MMMMM-d', '1970-S-1'),
@@ -859,6 +870,13 @@ public function parseErrorProvider()
859870
array('y-LLLLL-d', '1970-J-1'),
860871
array('y-LLLLL-d', '1970-S-1'),
861872
);
873+
874+
if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) {
875+
$data[] = array('y-M-d', '1970/1/1');
876+
$data[] = array('yy-M-d', '70/1/1');
877+
}
878+
879+
return $data;
862880
}
863881

864882
/**

tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,36 +142,41 @@ public function testFormatCurrencyWithCurrencyStyleIntl($value, $currency, $expe
142142

143143
public function formatCurrencyWithCurrencyStyleProvider()
144144
{
145-
return array(
145+
$data = array(
146146
array(100, 'ALL', 'ALL100'),
147147
array(-100, 'ALL', '(ALL100)'),
148148
array(1000.12, 'ALL', 'ALL1,000'),
149149

150-
array(100, 'BRL', 'R$100.00'),
151-
array(-100, 'BRL', '(R$100.00)'),
152-
array(1000.12, 'BRL', 'R$1,000.12'),
153-
154-
array(100, 'CRC', '₡100'),
155-
array(-100, 'CRC', '(₡100)'),
156-
array(1000.12, 'CRC', '₡1,000'),
157-
158150
array(100, 'JPY', '¥100'),
159151
array(-100, 'JPY', '(¥100)'),
160152
array(1000.12, 'JPY', '¥1,000'),
161153

162154
array(100, 'EUR', '€100.00'),
163155
array(-100, 'EUR', '(€100.00)'),
164156
array(1000.12, 'EUR', '€1,000.12'),
157+
);
165158

159+
if (!$this->isIntlExtensionLoaded() || !$this->isSameAsIcuVersion('4.8')) {
166160
// Rounding checks
167-
array(1000.121, 'BRL', 'R$1,000.12'),
168-
array(1000.123, 'BRL', 'R$1,000.12'),
169-
array(1000.125, 'BRL', 'R$1,000.12'),
170-
array(1000.127, 'BRL', 'R$1,000.13'),
171-
array(1000.129, 'BRL', 'R$1,000.13'),
172-
array(11.50999, 'BRL', 'R$11.51'),
173-
array(11.9999464, 'BRL', 'R$12.00')
174-
);
161+
$data[] = array(100, 'BRL', 'R$100.00');
162+
$data[] = array(-100, 'BRL', '(R$100.00)');
163+
$data[] = array(1000.12, 'BRL', 'R$1,000.12');
164+
$data[] = array(1000.121, 'BRL', 'R$1,000.12');
165+
$data[] = array(1000.123, 'BRL', 'R$1,000.12');
166+
$data[] = array(1000.125, 'BRL', 'R$1,000.12');
167+
$data[] = array(1000.127, 'BRL', 'R$1,000.13');
168+
$data[] = array(1000.129, 'BRL', 'R$1,000.13');
169+
$data[] = array(11.50999, 'BRL', 'R$11.51');
170+
$data[] = array(11.9999464, 'BRL', 'R$12.00');
171+
}
172+
173+
if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) {
174+
$data[] = array(100, 'CRC', '₡100');
175+
$data[] = array(-100, 'CRC', '(₡100)');
176+
$data[] = array(1000.12, 'CRC', '₡1,000');
177+
}
178+
179+
return $data;
175180
}
176181

177182
/**
@@ -180,7 +185,7 @@ public function formatCurrencyWithCurrencyStyleProvider()
180185
public function testFormatCurrencyWithCurrencyStyleSwissRoundingStub($value, $currency, $symbol, $expected)
181186
{
182187
$formatter = $this->getStubFormatterWithCurrencyStyle();
183-
$this->assertEquals(sprintf($expected, 'CHF'), $formatter->formatCurrency($value, $currency));
188+
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
184189
}
185190

186191
/**

tests/Symfony/Tests/Component/Locale/TestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ protected function isGreaterOrEqualThanIcuVersion($version)
7171
return $icuVersion >= $version;
7272
}
7373

74+
protected function isSameAsIcuVersion($version)
75+
{
76+
$version = $this->normalizeIcuVersion($version);
77+
$icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion());
78+
79+
return $icuVersion === $version;
80+
}
81+
7482
protected function isLowerThanIcuVersion($version)
7583
{
7684
$version = $this->normalizeIcuVersion($version);

0 commit comments

Comments
 (0)
0