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

Skip to content

Commit 90d6dc3

Browse files
committed
[Locale] fixed tests
1 parent 86da1b3 commit 90d6dc3

File tree

7 files changed

+86
-33
lines changed

7 files changed

+86
-33
lines changed

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

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

92-
$this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime));
92+
$expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT';
93+
94+
$this->assertEquals($expected, $transformer->transform($this->dateTime));
9395
}
9496

9597
public function testTransformFullTime()
@@ -100,7 +102,9 @@ public function testTransformFullTime()
100102

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

103-
$this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime));
105+
$expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT';
106+
107+
$this->assertEquals($expected, $transformer->transform($this->dateTime));
104108
}
105109

106110
public function testTransformToDifferentLocale()

src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ public function getReverseMatchingRegExp($pattern)
175175
{
176176
$that = $this;
177177

178-
$escapedPattern = preg_quote($pattern, '/');
178+
// $escapedPattern = preg_quote($pattern, '/');
179+
180+
// ICU 4.8 recognizes slash ("/") in a value to be parsed as a dash ("-") when parsing a value that
181+
// TODO: how to escape the regex metachars and still recognize "/" as "-" and vice-versa?
182+
$escapedPattern = preg_replace('/\-|\//', '[\/\-]', $pattern);
179183

180184
$reverseMatchingRegExp = preg_replace_callback($this->regExp, function($matches) use ($that) {
181185
$length = strlen($matches[0]);

src/Symfony/Component/Locale/Stub/DateFormat/TimeZoneTransformer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public function format(\DateTime $dateTime, $length)
3333
throw new NotImplementedException('Time zone different than GMT or UTC is not supported as a formatting output.');
3434
}
3535

36-
return $dateTime->format('\G\M\TP');
36+
// From ICU >= 4.8, the zero offset is not more used, example: GMT instead of GMT+00:00
37+
$format = (0 !== (int) $dateTime->format('O')) ? '\G\M\TP' : '\G\M\T';
38+
39+
return $dateTime->format($format);
3740
}
3841

3942
/**

src/Symfony/Component/Locale/Stub/StubLocale.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,23 @@ public static function setDefault($locale)
468468
throw new MethodNotImplementedException(__METHOD__);
469469
}
470470

471+
public static function getDataDirectory()
472+
{
473+
static $dataDirectory;
474+
475+
if (null === $dataDirectory) {
476+
$dataDirectory = 'current';
477+
478+
if (getenv('ICU_DATA_VERSION')) {
479+
$dataDirectory = getenv('ICU_DATA_VERSION');
480+
} elseif (file_exists(__DIR__.'/../Resources/data/data-version.php')) {
481+
$dataDirectory = include __DIR__.'/../Resources/data/data-version.php';
482+
}
483+
}
484+
485+
return __DIR__.'/../Resources/data/'.$dataDirectory;
486+
}
487+
471488
/**
472489
* Returns the stub ICU data
473490
*
@@ -488,7 +505,7 @@ private static function getStubData($locale, $cacheVariable, $stubDataDir)
488505
}
489506

490507
if (empty(self::${$cacheVariable})) {
491-
self::${$cacheVariable} = include __DIR__.'/../Resources/data/'.$dataDirectory.'/stub/'.$stubDataDir.'/en.php';
508+
self::${$cacheVariable} = include $dataDirectory.'/stub/'.$stubDataDir.'/en.php';
492509
}
493510

494511
return self::${$cacheVariable};

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

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ public function formatProvider()
121121
$formatData = array(
122122
/* general */
123123
array('y-M-d', 0, '1970-1-1'),
124-
array("yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 GMT+00:00'),
125124
array("EEE, MMM d, ''yy", 0, "Thu, Jan 1, '70"),
126125
array('h:mm a', 0, '12:00 AM'),
127-
array('K:mm a, z', 0, '0:00 AM, GMT+00:00'),
128126
array('yyyyy.MMMM.dd hh:mm aaa', 0, '01970.January.01 12:00 AM'),
129127

130128
/* escaping */
@@ -285,26 +283,36 @@ public function formatProvider()
285283
array('s', 3601, '1'),
286284
array('s', 3630, '30'),
287285
array('s', 43200, '0'), // 12 hours
288-
289-
/* timezone */
290-
array('z', 0, 'GMT+00:00'),
291-
array('zz', 0, 'GMT+00:00'),
292-
array('zzz', 0, 'GMT+00:00'),
293-
array('zzzz', 0, 'GMT+00:00'),
294-
array('zzzzz', 0, 'GMT+00:00'),
295286
);
296287

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

301306
/* general, DateTime */
302307
$formatData[] = array('y-M-d', $dateTime, '1970-1-1');
303-
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00');
304308
$formatData[] = array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70");
305309
$formatData[] = array('h:mm a', $dateTime, '12:00 AM');
306-
$formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00');
307310
$formatData[] = array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM');
311+
312+
if ($this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8')) {
313+
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT');
314+
$formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT');
315+
}
308316
}
309317

310318
return $formatData;
@@ -428,7 +436,9 @@ public function testFormatWithTimezoneFormatOptionAndDifferentThanUtcIntl()
428436
$this->skipIfIntlExtensionIsNotLoaded();
429437
$formatter = $this->createIntlFormatter('zzzz');
430438
$formatter->setTimeZoneId('Pacific/Fiji');
431-
$this->assertEquals('Fiji Time', $formatter->format(0));
439+
440+
$expected = $this->isGreaterOrEqualThanIcuVersion('49') ? 'Fiji Standard Time' : 'Fiji Time';
441+
$this->assertEquals($expected, $formatter->format(0));
432442
}
433443

434444
public function testFormatWithGmtTimezoneStub()
@@ -559,17 +569,22 @@ public function testDateAndTimeTypeIntl($timestamp, $datetype, $timetype, $expec
559569

560570
public function dateAndTimeTypeProvider()
561571
{
562-
return array(
572+
$data = array(
563573
array(0, StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, 'Thursday, January 1, 1970'),
564574
array(0, StubIntlDateFormatter::LONG, StubIntlDateFormatter::NONE, 'January 1, 1970'),
565575
array(0, StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::NONE, 'Jan 1, 1970'),
566576
array(0, StubIntlDateFormatter::SHORT, StubIntlDateFormatter::NONE, '1/1/70'),
567-
568-
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT+00:00'),
569-
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT+00:00'),
570-
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::MEDIUM, '12:00:00 AM'),
571-
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::SHORT, '12:00 AM'),
572577
);
578+
579+
if ($this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8')) {
580+
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT');
581+
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT');
582+
}
583+
584+
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::MEDIUM, '12:00:00 AM');
585+
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::SHORT, '12:00 AM');
586+
587+
return $data;
573588
}
574589

575590
public function testGetCalendar()
@@ -668,7 +683,7 @@ public function testParseStub($pattern, $value, $expected)
668683

669684
public function parseProvider()
670685
{
671-
return array(
686+
$data = array(
672687
// years
673688
array('y-M-d', '1970-1-1', 0),
674689
array('yy-M-d', '70-1-1', 0),
@@ -807,6 +822,15 @@ public function parseProvider()
807822
array("''y", "'1970", 0),
808823
array("H 'o'' clock'", "0 o' clock", 0),
809824
);
825+
826+
if ($this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8')) {
827+
$data[] = array('y-M-d', '1970/1/1', 0);
828+
$data[] = array('yy-M-d', '70/1/1', 0);
829+
$data[] = array('y/M/d', '1970-1-1', 0);
830+
$data[] = array('yy/M/d', '70-1-1', 0);
831+
}
832+
833+
return $data;
810834
}
811835

812836
/**
@@ -846,9 +870,6 @@ public function testParseErrorStub($pattern, $value)
846870
public function parseErrorProvider()
847871
{
848872
return array(
849-
array('y-M-d', '1970/1/1'),
850-
array('yy-M-d', '70/1/1'),
851-
852873
// 1 char month
853874
array('y-MMMMM-d', '1970-J-1'),
854875
array('y-MMMMM-d', '1970-S-1'),

src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
namespace Symfony\Component\Locale\Tests\Stub;
1313

14+
use Symfony\Component\Locale\Locale;
1415
use Symfony\Component\Locale\Stub\StubLocale;
16+
use Symfony\Component\Locale\Tests\TestCase as LocaleTestCase;
1517

16-
class StubLocaleTest extends \PHPUnit_Framework_TestCase
18+
class StubLocaleTest extends LocaleTestCase
1719
{
1820
/**
1921
* @expectedException InvalidArgumentException
@@ -65,8 +67,10 @@ public function testGetCurrenciesDataWithUnsupportedLocale()
6567

6668
public function testGetCurrenciesData()
6769
{
70+
$symbol = $this->isSameAsIcuVersion('4.8') ? 'BR$' : 'R$';
71+
6872
$currencies = StubLocale::getCurrenciesData('en');
69-
$this->assertEquals('R$', $currencies['BRL']['symbol']);
73+
$this->assertEquals($symbol, $currencies['BRL']['symbol']);
7074
$this->assertEquals('Brazilian Real', $currencies['BRL']['name']);
7175
$this->assertEquals(2, $currencies['BRL']['fractionDigits']);
7276
$this->assertEquals(0, $currencies['BRL']['roundingIncrement']);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function formatCurrencyWithCurrencyStyleProvider()
161161
public function testFormatCurrencyWithCurrencyStyleCostaRicanColonsRoundingStub($value, $currency, $symbol, $expected)
162162
{
163163
$formatter = $this->getStubFormatterWithCurrencyStyle();
164-
$this->assertEquals(sprintf($expected, ''), $formatter->formatCurrency($value, $currency));
164+
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
165165
}
166166

167167
/**
@@ -177,7 +177,7 @@ public function testFormatCurrencyWithCurrencyStyleCostaRicanColonsRoundingIntl(
177177

178178
public function formatCurrencyWithCurrencyStyleCostaRicanColonsRoundingProvider()
179179
{
180-
$crc = $this->isIntlExtensionLoaded() && $this->isSameAsIcuVersion('4.8') ? 'CRC' : '';
180+
$crc = $this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8') ? 'CRC' : '';
181181

182182
return array(
183183
array(100, 'CRC', $crc, '%s100'),
@@ -192,7 +192,7 @@ public function formatCurrencyWithCurrencyStyleCostaRicanColonsRoundingProvider(
192192
public function testFormatCurrencyWithCurrencyStyleBrazilianRealRoundingStub($value, $currency, $symbol, $expected)
193193
{
194194
$formatter = $this->getStubFormatterWithCurrencyStyle();
195-
$this->assertEquals(sprintf($expected, 'R'), $formatter->formatCurrency($value, $currency));
195+
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
196196
}
197197

198198
/**
@@ -232,7 +232,7 @@ public function formatCurrencyWithCurrencyStyleBrazilianRealRoundingProvider()
232232
public function testFormatCurrencyWithCurrencyStyleSwissRoundingStub($value, $currency, $symbol, $expected)
233233
{
234234
$formatter = $this->getStubFormatterWithCurrencyStyle();
235-
$this->assertEquals(sprintf($expected, 'CHF'), $formatter->formatCurrency($value, $currency));
235+
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
236236
}
237237

238238
/**

0 commit comments

Comments
 (0)
0