diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 147b39be32..c6628506c9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,6 +11,10 @@ syntaxCheck="false" bootstrap="tests/bootstrap.php" > + + + + ./tests/Symfony/ diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php index cf1a79321b..c0ae5ea143 100644 --- a/tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php +++ b/tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php @@ -91,7 +91,9 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase { $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::LONG); - $this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime)); + $expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT'; + + $this->assertEquals($expected, $transformer->transform($this->dateTime)); } public function testTransformFullTime() @@ -102,7 +104,9 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL); - $this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime)); + $expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT'; + + $this->assertEquals($expected, $transformer->transform($this->dateTime)); } public function testTransformToDifferentLocale() diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php index b3db625221..c99120998d 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php @@ -123,10 +123,8 @@ class StubIntlDateFormatterTest extends LocaleTestCase $formatData = array( /* general */ array('y-M-d', 0, '1970-1-1'), - array("yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 GMT+00:00'), array("EEE, MMM d, ''yy", 0, "Thu, Jan 1, '70"), array('h:mm a', 0, '12:00 AM'), - array('K:mm a, z', 0, '0:00 AM, GMT+00:00'), array('yyyyy.MMMM.dd hh:mm aaa', 0, '01970.January.01 12:00 AM'), /* escaping */ @@ -287,26 +285,36 @@ class StubIntlDateFormatterTest extends LocaleTestCase array('s', 3601, '1'), array('s', 3630, '30'), array('s', 43200, '0'), // 12 hours - - /* timezone */ - array('z', 0, 'GMT+00:00'), - array('zz', 0, 'GMT+00:00'), - array('zzz', 0, 'GMT+00:00'), - array('zzzz', 0, 'GMT+00:00'), - array('zzzzz', 0, 'GMT+00:00'), ); + // Timezone + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + // general + $formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 GMT+00:00'); + $formatData[] = array('K:mm a, z', 0, '0:00 AM, GMT+00:00'); + + // timezone + $formatData[] = array('z', 0, 'GMT+00:00'); + $formatData[] = array('zz', 0, 'GMT+00:00'); + $formatData[] = array('zzz', 0, 'GMT+00:00'); + $formatData[] = array('zzzz', 0, 'GMT+00:00'); + $formatData[] = array('zzzzz', 0, 'GMT+00:00'); + } + // As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances if ($this->isGreaterOrEqualThanPhpVersion('5.3.4')) { $dateTime = new \DateTime('@0'); /* general, DateTime */ $formatData[] = array('y-M-d', $dateTime, '1970-1-1'); - $formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00'); $formatData[] = array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70"); $formatData[] = array('h:mm a', $dateTime, '12:00 AM'); - $formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00'); $formatData[] = array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM'); + + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + $formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00'); + $formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00'); + } } return $formatData; @@ -430,7 +438,9 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->skipIfIntlExtensionIsNotLoaded(); $formatter = $this->createIntlFormatter('zzzz'); $formatter->setTimeZoneId('Pacific/Fiji'); - $this->assertEquals('Fiji Time', $formatter->format(0)); + + $expected = $this->isGreaterOrEqualThanIcuVersion('49') ? 'Fiji Standard Time' : 'Fiji Time'; + $this->assertEquals($expected, $formatter->format(0)); } public function testFormatWithGmtTimezoneStub() @@ -464,7 +474,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->skipIfIntlExtensionIsNotLoaded(); $this->skipIfICUVersionIsTooOld(); - $formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT); + $formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC'); $formatter->setPattern('yyyy-MM-dd HH:mm:ss'); $this->assertEquals( @@ -493,7 +503,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase } /** - * It seems IntlDateFormatter caches the timezone id when not explicitely set via constructor or by the + * It seems IntlDateFormatter caches the timezone id when not explicitly set via constructor or by the * setTimeZoneId() method. Since testFormatWithDefaultTimezoneIntl() runs using the default environment * time zone, this test would use it too if not running in a separated process. * @@ -561,17 +571,21 @@ class StubIntlDateFormatterTest extends LocaleTestCase public function dateAndTimeTypeProvider() { - return array( + $data = array( array(0, StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, 'Thursday, January 1, 1970'), array(0, StubIntlDateFormatter::LONG, StubIntlDateFormatter::NONE, 'January 1, 1970'), array(0, StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::NONE, 'Jan 1, 1970'), array(0, StubIntlDateFormatter::SHORT, StubIntlDateFormatter::NONE, '1/1/70'), - - array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT+00:00'), - array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT+00:00'), array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::MEDIUM, '12:00:00 AM'), array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::SHORT, '12:00 AM'), ); + + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + $data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT+00:00'); + $data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT+00:00'); + } + + return $data; } public function testGetCalendar() @@ -847,10 +861,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase public function parseErrorProvider() { - return array( - array('y-M-d', '1970/1/1'), - array('yy-M-d', '70/1/1'), - + $data = array( // 1 char month array('y-MMMMM-d', '1970-J-1'), array('y-MMMMM-d', '1970-S-1'), @@ -859,6 +870,13 @@ class StubIntlDateFormatterTest extends LocaleTestCase array('y-LLLLL-d', '1970-J-1'), array('y-LLLLL-d', '1970-S-1'), ); + + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + $data[] = array('y-M-d', '1970/1/1'); + $data[] = array('yy-M-d', '70/1/1'); + } + + return $data; } /** diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php index bb9fc85991..7fc2402c3d 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php @@ -142,19 +142,11 @@ class StubNumberFormatterTest extends LocaleTestCase public function formatCurrencyWithCurrencyStyleProvider() { - return array( + $data = array( array(100, 'ALL', 'ALL100'), array(-100, 'ALL', '(ALL100)'), array(1000.12, 'ALL', 'ALL1,000'), - array(100, 'BRL', 'R$100.00'), - array(-100, 'BRL', '(R$100.00)'), - array(1000.12, 'BRL', 'R$1,000.12'), - - array(100, 'CRC', '₡100'), - array(-100, 'CRC', '(₡100)'), - array(1000.12, 'CRC', '₡1,000'), - array(100, 'JPY', '¥100'), array(-100, 'JPY', '(¥100)'), array(1000.12, 'JPY', '¥1,000'), @@ -162,16 +154,29 @@ class StubNumberFormatterTest extends LocaleTestCase array(100, 'EUR', '€100.00'), array(-100, 'EUR', '(€100.00)'), array(1000.12, 'EUR', '€1,000.12'), - - // Rounding checks - array(1000.121, 'BRL', 'R$1,000.12'), - array(1000.123, 'BRL', 'R$1,000.12'), - array(1000.125, 'BRL', 'R$1,000.12'), - array(1000.127, 'BRL', 'R$1,000.13'), - array(1000.129, 'BRL', 'R$1,000.13'), - array(11.50999, 'BRL', 'R$11.51'), - array(11.9999464, 'BRL', 'R$12.00') ); + + if (!$this->isIntlExtensionLoaded() || !$this->isSameAsIcuVersion('4.8')) { + // Rounding checks + $data[] = array(100, 'BRL', 'R$100.00'); + $data[] = array(-100, 'BRL', '(R$100.00)'); + $data[] = array(1000.12, 'BRL', 'R$1,000.12'); + $data[] = array(1000.121, 'BRL', 'R$1,000.12'); + $data[] = array(1000.123, 'BRL', 'R$1,000.12'); + $data[] = array(1000.125, 'BRL', 'R$1,000.12'); + $data[] = array(1000.127, 'BRL', 'R$1,000.13'); + $data[] = array(1000.129, 'BRL', 'R$1,000.13'); + $data[] = array(11.50999, 'BRL', 'R$11.51'); + $data[] = array(11.9999464, 'BRL', 'R$12.00'); + } + + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + $data[] = array(100, 'CRC', '₡100'); + $data[] = array(-100, 'CRC', '(₡100)'); + $data[] = array(1000.12, 'CRC', '₡1,000'); + } + + return $data; } /** @@ -180,7 +185,7 @@ class StubNumberFormatterTest extends LocaleTestCase public function testFormatCurrencyWithCurrencyStyleSwissRoundingStub($value, $currency, $symbol, $expected) { $formatter = $this->getStubFormatterWithCurrencyStyle(); - $this->assertEquals(sprintf($expected, 'CHF'), $formatter->formatCurrency($value, $currency)); + $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency)); } /** diff --git a/tests/Symfony/Tests/Component/Locale/TestCase.php b/tests/Symfony/Tests/Component/Locale/TestCase.php index 8df87e447b..3ee1c60449 100644 --- a/tests/Symfony/Tests/Component/Locale/TestCase.php +++ b/tests/Symfony/Tests/Component/Locale/TestCase.php @@ -71,6 +71,14 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase return $icuVersion >= $version; } + protected function isSameAsIcuVersion($version) + { + $version = $this->normalizeIcuVersion($version); + $icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion()); + + return $icuVersion === $version; + } + protected function isLowerThanIcuVersion($version) { $version = $this->normalizeIcuVersion($version);