|
@@ -53,52 +53,69 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|
|
$this->assertNull($formatter->getTimeZoneId());
|
|
|
}
|
|
|
|
|
|
+ public function testFormatWithUnsupportedTimestampArgument()
|
|
|
+ {
|
|
|
+ $formatter = $this->createStubFormatter();
|
|
|
+
|
|
|
+ $localtime = array(
|
|
|
+ 'tm_sec' => 59,
|
|
|
+ 'tm_min' => 3,
|
|
|
+ 'tm_hour' => 15,
|
|
|
+ 'tm_mday' => 15,
|
|
|
+ 'tm_mon' => 3,
|
|
|
+ 'tm_year' => 112,
|
|
|
+ 'tm_wday' => 0,
|
|
|
+ 'tm_yday' => 105,
|
|
|
+ 'tm_isdst' => 0
|
|
|
+ );
|
|
|
+
|
|
|
+ try {
|
|
|
+ $formatter->format($localtime);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->assertInstanceOf('Symfony\Component\Locale\Exception\MethodArgumentValueNotImplementedException', $e);
|
|
|
+
|
|
|
+ if ($this->isGreaterOrEqualThanPhpVersion('5.3.4')) {
|
|
|
+ $this->assertStringEndsWith('Only integer unix timestamps and DateTime objects are supported. Please install the \'intl\' extension for full localization capabilities.', $e->getMessage());
|
|
|
+ } else {
|
|
|
+ $this->assertStringEndsWith('Only integer unix timestamps are supported. Please install the \'intl\' extension for full localization capabilities.', $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @dataProvider formatProvider
|
|
|
*/
|
|
|
- public function testFormatStub($pattern, $timestamp, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR')
|
|
|
+ public function testFormatStub($pattern, $timestamp, $expected)
|
|
|
{
|
|
|
+ $errorCode = StubIntl::U_ZERO_ERROR;
|
|
|
+ $errorMessage = 'U_ZERO_ERROR';
|
|
|
+
|
|
|
$formatter = $this->createStubFormatter($pattern);
|
|
|
$this->assertSame($expected, $formatter->format($timestamp));
|
|
|
$this->assertSame($errorMessage, StubIntl::getErrorMessage());
|
|
|
$this->assertSame($errorCode, StubIntl::getErrorCode());
|
|
|
- $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode()));
|
|
|
+ $this->assertFalse(StubIntl::isFailure(StubIntl::getErrorCode()));
|
|
|
$this->assertSame($errorMessage, $formatter->getErrorMessage());
|
|
|
$this->assertSame($errorCode, $formatter->getErrorCode());
|
|
|
- $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode()));
|
|
|
+ $this->assertFalse(StubIntl::isFailure($formatter->getErrorCode()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @dataProvider formatProvider
|
|
|
*/
|
|
|
- public function testFormatIntl($pattern, $timestamp, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR')
|
|
|
+ public function testFormatIntl($pattern, $timestamp, $expected)
|
|
|
{
|
|
|
$this->skipIfIntlExtensionIsNotLoaded();
|
|
|
$this->skipIfICUVersionIsTooOld();
|
|
|
- $formatter = $this->createIntlFormatter($pattern);
|
|
|
- $this->assertSame($expected, $formatter->format($timestamp));
|
|
|
- $this->assertSame($errorMessage, intl_get_error_message());
|
|
|
- $this->assertSame($errorCode, intl_get_error_code());
|
|
|
- $this->assertSame($errorCode != 0, intl_is_failure(intl_get_error_code()));
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * @dataProvider formatErrorProvider
|
|
|
- */
|
|
|
- public function testFormatErrorIntl($pattern, $timestamp, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR')
|
|
|
- {
|
|
|
- $this->skipIfIntlExtensionIsNotLoaded();
|
|
|
- $this->skipIfICUVersionIsTooOld();
|
|
|
-
|
|
|
- if (version_compare(PHP_VERSION, '5.3.3') > 0) {
|
|
|
- $this->markTestSkipped('The intl error messages were change in PHP 5.3.3.');
|
|
|
- }
|
|
|
+ $errorCode = StubIntl::U_ZERO_ERROR;
|
|
|
+ $errorMessage = 'U_ZERO_ERROR';
|
|
|
|
|
|
$formatter = $this->createIntlFormatter($pattern);
|
|
|
$this->assertSame($expected, $formatter->format($timestamp));
|
|
|
$this->assertSame($errorMessage, intl_get_error_message());
|
|
|
$this->assertSame($errorCode, intl_get_error_code());
|
|
|
- $this->assertSame($errorCode != 0, intl_is_failure(intl_get_error_code()));
|
|
|
+ $this->assertFalse(intl_is_failure(intl_get_error_code()));
|
|
|
}
|
|
|
|
|
|
public function formatProvider()
|
|
@@ -280,7 +297,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|
|
);
|
|
|
|
|
|
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
|
|
|
- if (version_compare(\PHP_VERSION, '5.3.4', '>=')) {
|
|
|
+ if ($this->isGreaterOrEqualThanPhpVersion('5.3.4')) {
|
|
|
$dateTime = new \DateTime('@0');
|
|
|
|
|
|
/* general, DateTime */
|
|
@@ -295,13 +312,51 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|
|
return $formatData;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @dataProvider formatErrorProvider
|
|
|
+ */
|
|
|
+ public function testFormatIllegalArgumentErrorStub($pattern, $timestamp, $errorMessage)
|
|
|
+ {
|
|
|
+ $errorCode = StubIntl::U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
+
|
|
|
+ $formatter = $this->createStubFormatter($pattern);
|
|
|
+ $this->assertFalse($formatter->format($timestamp));
|
|
|
+ $this->assertSame($errorMessage, StubIntl::getErrorMessage());
|
|
|
+ $this->assertSame($errorCode, StubIntl::getErrorCode());
|
|
|
+ $this->assertTrue(StubIntl::isFailure(StubIntl::getErrorCode()));
|
|
|
+ $this->assertSame($errorMessage, $formatter->getErrorMessage());
|
|
|
+ $this->assertSame($errorCode, $formatter->getErrorCode());
|
|
|
+ $this->assertTrue(StubIntl::isFailure($formatter->getErrorCode()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @dataProvider formatErrorProvider
|
|
|
+ */
|
|
|
+ public function testFormatIllegalArgumentErrorIntl($pattern, $timestamp, $errorMessage)
|
|
|
+ {
|
|
|
+ $this->skipIfIntlExtensionIsNotLoaded();
|
|
|
+ $this->skipIfICUVersionIsTooOld();
|
|
|
+
|
|
|
+ $errorCode = StubIntl::U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
+
|
|
|
+ $formatter = $this->createIntlFormatter($pattern);
|
|
|
+ $this->assertFalse($formatter->format($timestamp));
|
|
|
+ $this->assertSame($errorMessage, intl_get_error_message());
|
|
|
+ $this->assertSame($errorCode, intl_get_error_code());
|
|
|
+ $this->assertTrue(intl_is_failure(intl_get_error_code()));
|
|
|
+ }
|
|
|
+
|
|
|
public function formatErrorProvider()
|
|
|
{
|
|
|
- /* errors */
|
|
|
+ $message = 'datefmt_format: takes either an array or an integer timestamp value : U_ILLEGAL_ARGUMENT_ERROR';
|
|
|
+
|
|
|
+ if ($this->isGreaterOrEqualThanPhpVersion('5.3.4')) {
|
|
|
+ $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', '0', false, 1, 'datefmt_format: takes either an array or an integer timestamp value : U_ILLEGAL_ARGUMENT_ERROR'),
|
|
|
- array('y-M-d', 'foobar', false, 1, 'datefmt_format: takes either an array or an integer timestamp value : U_ILLEGAL_ARGUMENT_ERROR'),
|
|
|
+ array('y-M-d', '0', $message),
|
|
|
+ array('y-M-d', 'foobar', $message),
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -543,7 +598,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|
|
$this->assertSame($expected, $formatter->parse($value));
|
|
|
$this->assertSame($errorMessage, intl_get_error_message());
|
|
|
$this->assertSame($errorCode, intl_get_error_code());
|
|
|
- $this->assertSame($errorCode != 0, intl_is_failure(intl_get_error_code()));
|
|
|
+ $this->assertFalse(intl_is_failure(intl_get_error_code()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -558,10 +613,10 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|
|
$this->assertSame($expected, $formatter->parse($value));
|
|
|
$this->assertSame($errorMessage, StubIntl::getErrorMessage());
|
|
|
$this->assertSame($errorCode, StubIntl::getErrorCode());
|
|
|
- $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode()));
|
|
|
+ $this->assertFalse(StubIntl::isFailure(StubIntl::getErrorCode()));
|
|
|
$this->assertSame($errorMessage, $formatter->getErrorMessage());
|
|
|
$this->assertSame($errorCode, $formatter->getErrorCode());
|
|
|
- $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode()));
|
|
|
+ $this->assertFalse(StubIntl::isFailure($formatter->getErrorCode()));
|
|
|
}
|
|
|
|
|
|
public function parseProvider()
|
|
@@ -720,7 +775,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|
|
$this->assertFalse($formatter->parse($value));
|
|
|
$this->assertSame($errorMessage, intl_get_error_message());
|
|
|
$this->assertSame($errorCode, intl_get_error_code());
|
|
|
- $this->assertSame($errorCode != 0, intl_is_failure(intl_get_error_code()));
|
|
|
+ $this->assertTrue(intl_is_failure(intl_get_error_code()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -735,10 +790,10 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|
|
$this->assertFalse($formatter->parse($value));
|
|
|
$this->assertSame($errorMessage, StubIntl::getErrorMessage());
|
|
|
$this->assertSame($errorCode, StubIntl::getErrorCode());
|
|
|
- $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode()));
|
|
|
+ $this->assertTrue(StubIntl::isFailure(StubIntl::getErrorCode()));
|
|
|
$this->assertSame($errorMessage, $formatter->getErrorMessage());
|
|
|
$this->assertSame($errorCode, $formatter->getErrorCode());
|
|
|
- $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode()));
|
|
|
+ $this->assertTrue(StubIntl::isFailure($formatter->getErrorCode()));
|
|
|
}
|
|
|
|
|
|
public function parseErrorProvider()
|