summaryrefslogtreecommitdiff
path: root/vendor/symfony/intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php')
-rw-r--r--vendor/symfony/intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php117
1 files changed, 97 insertions, 20 deletions
diff --git a/vendor/symfony/intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php b/vendor/symfony/intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php
index e1298e6d6b..76c3c79f47 100644
--- a/vendor/symfony/intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php
+++ b/vendor/symfony/intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php
@@ -35,7 +35,12 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
{
$formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
- $this->assertEquals(date_default_timezone_get(), $formatter->getTimeZoneId());
+ // In PHP 5.5 default timezone depends on `date_default_timezone_get()` method
+ if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ $this->assertEquals(date_default_timezone_get(), $formatter->getTimeZoneId());
+ } else {
+ $this->assertNull($formatter->getTimeZoneId());
+ }
$this->assertEquals(
$this->getDateTime(0, $formatter->getTimeZoneId())->format('M j, Y, g:i A'),
@@ -58,8 +63,6 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
public function formatProvider()
{
- $dateTime = new \DateTime('@0');
-
$formatData = array(
/* general */
array('y-M-d', 0, '1970-1-1'),
@@ -236,16 +239,19 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
array('zzz', 0, 'GMT'),
array('zzzz', 0, 'GMT'),
array('zzzzz', 0, 'GMT'),
-
- // general, DateTime
- array('y-M-d', $dateTime, '1970-1-1'),
- array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70"),
- array('h:mm a', $dateTime, '12:00 AM'),
- array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM'),
- array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT'),
- array('K:mm a, z', $dateTime, '0:00 AM, GMT'),
);
+ $dateTime = new \DateTime('@0');
+
+ /* general, DateTime */
+ $formatData[] = array('y-M-d', $dateTime, '1970-1-1');
+ $formatData[] = array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70");
+ $formatData[] = array('h:mm a', $dateTime, '12:00 AM');
+ $formatData[] = array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM');
+
+ $formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT');
+ $formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT');
+
return $formatData;
}
@@ -263,8 +269,18 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
public function formatErrorProvider()
{
+ // With PHP 5.5 IntlDateFormatter accepts empty values ('0')
+ if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ return array(
+ array('y-M-d', 'foobar', 'datefmt_format: string \'foobar\' is not numeric, which would be required for it to be a valid date: U_ILLEGAL_ARGUMENT_ERROR'),
+ );
+ }
+
+ $message = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object: U_ILLEGAL_ARGUMENT_ERROR';
+
return array(
- array('y-M-d', 'foobar', 'datefmt_format: string \'foobar\' is not numeric, which would be required for it to be a valid date: U_ILLEGAL_ARGUMENT_ERROR'),
+ array('y-M-d', '0', $message),
+ array('y-M-d', 'foobar', $message),
);
}
@@ -306,6 +322,14 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
array(0, 'Pacific/Fiji', '1970-01-01 12:00:00'),
);
+ // As of PHP 5.5, intl ext no longer fallbacks invalid time zones to UTC
+ if (PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ // When time zone not exists, uses UTC by default
+ $data[] = array(0, 'Foo/Bar', '1970-01-01 00:00:00');
+ $data[] = array(0, 'UTC+04:30', '1970-01-01 00:00:00');
+ $data[] = array(0, 'UTC+04:AA', '1970-01-01 00:00:00');
+ }
+
return $data;
}
@@ -313,7 +337,11 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
{
$formatter = $this->getDefaultDateFormatter('zzzz');
- $formatter->setTimeZone('GMT+03:00');
+ if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ $formatter->setTimeZone('GMT+03:00');
+ } else {
+ $formatter->setTimeZoneId('GMT+03:00');
+ }
$this->assertEquals('GMT+03:00', $formatter->format(0));
}
@@ -322,7 +350,11 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
{
$formatter = $this->getDefaultDateFormatter('zzzz');
- $formatter->setTimeZone('GMT+00:30');
+ if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ $formatter->setTimeZone('GMT+00:30');
+ } else {
+ $formatter->setTimeZoneId('GMT+00:30');
+ }
$this->assertEquals('GMT+00:30', $formatter->format(0));
}
@@ -331,7 +363,11 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
{
$formatter = $this->getDefaultDateFormatter('zzzz');
- $formatter->setTimeZone('Pacific/Fiji');
+ if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ $formatter->setTimeZone('Pacific/Fiji');
+ } else {
+ $formatter->setTimeZoneId('Pacific/Fiji');
+ }
$this->assertEquals('Fiji Standard Time', $formatter->format(0));
}
@@ -349,6 +385,10 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
public function testFormatWithDateTimeZoneGmt()
{
+ if (PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ $this->markTestSkipped('Only in PHP 5.5+ IntlDateFormatter allows to use DateTimeZone objects.');
+ }
+
$formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, new \DateTimeZone('GMT'), IntlDateFormatter::GREGORIAN, 'zzzz');
$this->assertEquals('GMT', $formatter->format(0));
@@ -370,13 +410,44 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
*/
public function testFormatWithIntlTimeZone()
{
+ if (PHP_VERSION_ID < 50500 && !method_exists('IntlDateFormatter', 'setTimeZone')) {
+ $this->markTestSkipped('Only in PHP 5.5+ IntlDateFormatter allows to use DateTimeZone objects.');
+ }
+
$formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, \IntlTimeZone::createTimeZone('GMT+03:00'), IntlDateFormatter::GREGORIAN, 'zzzz');
$this->assertEquals('GMT+03:00', $formatter->format(0));
}
+ public function testFormatWithTimezoneFromEnvironmentVariable()
+ {
+ if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ $this->markTestSkipped('IntlDateFormatter in PHP 5.5 no longer depends on TZ environment.');
+ }
+
+ $tz = getenv('TZ');
+ putenv('TZ=Europe/London');
+
+ $formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT);
+ $formatter->setPattern('yyyy-MM-dd HH:mm:ss');
+
+ $this->assertEquals(
+ $this->getDateTime(0, 'Europe/London')->format('Y-m-d H:i:s'),
+ $formatter->format(0)
+ );
+
+ $this->assertEquals('Europe/London', getenv('TZ'));
+
+ // Restores TZ.
+ putenv('TZ='.$tz);
+ }
+
public function testFormatWithTimezoneFromPhp()
{
+ if (PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ $this->markTestSkipped('Only in PHP 5.5 IntlDateFormatter depends on default timezone (`date_default_timezone_get()`).');
+ }
+
$tz = date_default_timezone_get();
date_default_timezone_set('Europe/London');
@@ -803,22 +874,28 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
{
$formatter = $this->getDefaultDateFormatter();
- $formatter->setTimeZone($timeZoneId);
+ if (PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
+ $formatter->setTimeZone($timeZoneId);
+ } else {
+ $formatter->setTimeZoneId($timeZoneId);
+ }
$this->assertEquals($expectedTimeZoneId, $formatter->getTimeZoneId());
}
public function setTimeZoneIdProvider()
{
+ $isPhp55 = PHP_VERSION_ID >= 50500 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'));
+
return array(
array('UTC', 'UTC'),
array('GMT', 'GMT'),
array('GMT-03:00', 'GMT-03:00'),
array('Europe/Zurich', 'Europe/Zurich'),
- array(null, date_default_timezone_get()),
- array('Foo/Bar', 'UTC'),
- array('GMT+00:AA', 'UTC'),
- array('GMT+00AA', 'UTC'),
+ array(null, $isPhp55 ? date_default_timezone_get() : null),
+ array('Foo/Bar', $isPhp55 ? 'UTC' : 'Foo/Bar'),
+ array('GMT+00:AA', $isPhp55 ? 'UTC' : 'GMT+00:AA'),
+ array('GMT+00AA', $isPhp55 ? 'UTC' : 'GMT+00AA'),
);
}