From 089188f6035619abc04cfdc5736f8e2a8eaaa510 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Fri, 13 Apr 2012 21:40:36 +0100 Subject: [PATCH 01/14] [Validator] Fixed StaticMethodLoader when used with abstract methods. --- .../Validator/Mapping/Loader/StaticMethodLoader.php | 2 +- .../Mapping/Loader/StaticMethodLoaderTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Mapping/Loader/StaticMethodLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/StaticMethodLoader.php index a74ffbb429..3e90fe91b5 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/StaticMethodLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/StaticMethodLoader.php @@ -37,7 +37,7 @@ class StaticMethodLoader implements LoaderInterface throw new MappingException(sprintf('The method %s::%s should be static', $reflClass->getName(), $this->methodName)); } - if ($reflMethod->getDeclaringClass()->getName() != $reflClass->getName()) { + if ($reflClass->isAbstract() || $reflMethod->getDeclaringClass()->getName() != $reflClass->getName()) { return false; } diff --git a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/StaticMethodLoaderTest.php b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/StaticMethodLoaderTest.php index daaf89f6e9..6d4493a753 100644 --- a/tests/Symfony/Tests/Component/Validator/Mapping/Loader/StaticMethodLoaderTest.php +++ b/tests/Symfony/Tests/Component/Validator/Mapping/Loader/StaticMethodLoaderTest.php @@ -35,6 +35,14 @@ class StaticMethodLoaderTest extends \PHPUnit_Framework_TestCase $this->assertFalse($loader->loadClassMetadata($metadata)); } + public function testLoadClassMetadataReturnsFalseIfMethodIsAbstract() + { + $loader = new StaticMethodLoader('loadMetadata'); + $metadata = new ClassMetadata(__NAMESPACE__.'\AbstractStaticLoaderEntity'); + + $this->assertFalse($loader->loadClassMetadata($metadata)); + } + public function testLoadClassMetadata() { $loader = new StaticMethodLoader('loadMetadata'); @@ -80,3 +88,8 @@ class BaseStaticLoaderDocument $metadata->addConstraint(new ConstraintA()); } } + +abstract class AbstractStaticLoaderEntity +{ + abstract public static function loadMetadata(ClassMetadata $metadata); +} From 05b223817e82d221ef6334e767a01fa01a55fa86 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Sat, 14 Apr 2012 12:56:35 +0200 Subject: [PATCH 02/14] [DependencyInjection] Fix for issue introduced in 3ae826a --- .../Component/DependencyInjection/Loader/YamlFileLoader.php | 5 +++-- .../DependencyInjection/Loader/YamlFileLoaderTest.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 8433d53cde..7f770fa0f8 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Yaml\Yaml; @@ -205,12 +206,12 @@ class YamlFileLoader extends FileLoader if (isset($service['tags'])) { if (!is_array($service['tags'])) { - throw new \InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s.', $id, $file)); + throw new InvalidArgumentException(sprintf('Parameter "tags" must be an array for service "%s" in %s.', $id, $file)); } foreach ($service['tags'] as $tag) { if (!isset($tag['name'])) { - throw new \InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file)); + throw new InvalidArgumentException(sprintf('A "tags" entry is missing a "name" key for service "%s" in %s.', $id, $file)); } $name = $tag['name']; diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php index 2d952c655e..bd84b3f5ca 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Loader/YamlFileLoaderTest.php @@ -169,7 +169,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase $loader->load('badtag1.yml'); $this->fail('->load() should throw an exception when the tags key of a service is not an array'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tags key is not an array'); + $this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tags key is not an array'); $this->assertStringStartsWith('Parameter "tags" must be an array for service', $e->getMessage(), '->load() throws an InvalidArgumentException if the tags key is not an array'); } } @@ -181,7 +181,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase $loader->load('badtag2.yml'); $this->fail('->load() should throw an exception when a tag is missing the name key'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if a tag is missing the name key'); + $this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if a tag is missing the name key'); $this->assertStringStartsWith('A "tags" entry is missing a "name" key for service ', $e->getMessage(), '->load() throws an InvalidArgumentException if a tag is missing the name key'); } } From bb61e09340c5d3dbea511032ca8f66be796f257c Mon Sep 17 00:00:00 2001 From: stealth35 Date: Sat, 14 Apr 2012 17:11:17 -0300 Subject: [PATCH 03/14] [Locale] use the correct way for Intl error --- .../Stub/DateFormat/FullTransformer.php | 4 +-- .../Component/Locale/Stub/StubIntl.php | 36 +++++++++---------- .../Locale/Stub/StubIntlDateFormatter.php | 31 ++++++++++------ .../Locale/Stub/StubNumberFormatter.php | 35 +++++++----------- .../Locale/Stub/StubIntlDateFormatterTest.php | 17 ++++++--- .../Locale/Stub/StubNumberFormatterTest.php | 7 ++-- 6 files changed, 68 insertions(+), 62 deletions(-) diff --git a/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php b/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php index 5cb50e76a9..c13b1a330c 100644 --- a/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php +++ b/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php @@ -155,7 +155,7 @@ class FullTransformer } // behave like the intl extension - StubIntl::setErrorCode(StubIntl::U_PARSE_ERROR); + StubIntl::setErrorCode(StubIntl::U_PARSE_ERROR, 'Date parsing failed'); return false; } @@ -292,7 +292,7 @@ class FullTransformer // If month is false, return immediately (intl behavior) if (false === $month) { - StubIntl::setErrorCode(StubIntl::U_PARSE_ERROR); + StubIntl::setErrorCode(StubIntl::U_PARSE_ERROR, 'Date parsing failed'); return false; } diff --git a/src/Symfony/Component/Locale/Stub/StubIntl.php b/src/Symfony/Component/Locale/Stub/StubIntl.php index bb00ade862..509e1ee494 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntl.php +++ b/src/Symfony/Component/Locale/Stub/StubIntl.php @@ -45,20 +45,9 @@ abstract class StubIntl * @var array */ private static $errorCodes = array( - self::U_ZERO_ERROR, - self::U_ILLEGAL_ARGUMENT_ERROR, - self::U_PARSE_ERROR, - ); - - /** - * The error messages of all known error codes - * - * @var array - */ - private static $errorMessages = array( self::U_ZERO_ERROR => 'U_ZERO_ERROR', - self::U_ILLEGAL_ARGUMENT_ERROR => 'datefmt_format: takes either an array or an integer timestamp value : U_ILLEGAL_ARGUMENT_ERROR', - self::U_PARSE_ERROR => 'Date parsing failed: U_PARSE_ERROR', + self::U_ILLEGAL_ARGUMENT_ERROR => 'U_ILLEGAL_ARGUMENT_ERROR', + self::U_PARSE_ERROR => 'U_PARSE_ERROR', ); /** @@ -68,6 +57,13 @@ abstract class StubIntl */ private static $errorCode = self::U_ZERO_ERROR; + /** + * The error code of the last operation + * + * @var integer + */ + private static $errorMessage = 'U_ZERO_ERROR'; + /** * Returns whether the error code indicates a failure * @@ -77,8 +73,8 @@ abstract class StubIntl */ static public function isFailure($errorCode) { - return in_array($errorCode, self::$errorCodes, true) - && $errorCode !== self::U_ZERO_ERROR; + return array_key_exists($errorCode, self::$errorCodes) + && $errorCode > self::U_ZERO_ERROR; } /** @@ -102,22 +98,24 @@ abstract class StubIntl */ static public function getErrorMessage() { - return self::$errorMessages[self::$errorCode]; + return self::$errorMessage; } /** * Sets the current error code * - * @param integer $code One of the error constants in this class + * @param integer $code One of the error constants in this class + * @param string $message The ICU class error message * * @throws \InvalidArgumentException If the code is not one of the error constants in this class */ - static public function setErrorCode($code) + static public function setErrorCode($code, $message = '') { - if (!isset(self::$errorMessages[$code])) { + if (!isset(self::$errorCodes[$code])) { throw new \InvalidArgumentException(sprintf('No such error code: "%s"', $code)); } + self::$errorMessage = $message ? sprintf('%s: %s', $message, self::$errorCodes[$code]) : self::$errorCodes[$code]; self::$errorCode = $code; } } diff --git a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php index edc952094f..10392c052d 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php @@ -26,14 +26,18 @@ use Symfony\Component\Locale\Exception\MethodArgumentValueNotImplementedExceptio class StubIntlDateFormatter { /** - * Constants defined by the intl extension, not class constants in IntlDateFormatter - * TODO: remove if the Form component drop the call to the intl_is_failure() function + * The error code from the last operation * - * @see StubIntlDateFormatter::getErrorCode() - * @see StubIntlDateFormatter::getErrorMessage() + * @var integer */ - const U_ZERO_ERROR = 0; - const U_ZERO_ERROR_MESSAGE = 'U_ZERO_ERROR'; + protected $errorCode = StubIntl::U_ZERO_ERROR; + + /** + * The error message from the last operation + * + * @var string + */ + protected $errorMessage = 'U_ZERO_ERROR'; /* date/time format types */ const NONE = -1; @@ -225,7 +229,7 @@ class StubIntlDateFormatter */ public function getErrorCode() { - return self::U_ZERO_ERROR; + return $this->errorCode; } /** @@ -237,7 +241,7 @@ class StubIntlDateFormatter */ public function getErrorMessage() { - return self::U_ZERO_ERROR_MESSAGE; + return $this->errorMessage; } /** @@ -350,12 +354,17 @@ class StubIntlDateFormatter throw new MethodArgumentNotImplementedException(__METHOD__, 'position'); } - StubIntl::setErrorCode(StubIntl::U_ZERO_ERROR); - $dateTime = $this->createDateTime(0); $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId()); - return $transformer->parse($dateTime, $value); + $timestamp = $transformer->parse($dateTime, $value); + + if (false === $timestamp) { + $this->errorCode = StubIntl::getErrorCode(); + $this->errorMessage = StubIntl::getErrorMessage(); + } + + return $timestamp; } /** diff --git a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php index d7accea3cc..ad72c2183d 100644 --- a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php @@ -24,32 +24,19 @@ use Symfony\Component\Locale\Exception\MethodArgumentValueNotImplementedExceptio */ class StubNumberFormatter { - /** - * Constants defined by the intl extension, not class constants in NumberFormatter - * TODO: remove if the Form component drop the call to the intl_is_failure() function - * - * @see StubNumberFormatter::getErrorCode() - * @see StubNumberFormatter::getErrorMessage() - */ - const U_ZERO_ERROR = 0; - const U_PARSE_ERROR = 9; - - /** - * The error messages for each error code - * - * @var array - */ - protected $errorMessages = array( - self::U_ZERO_ERROR => 'U_ZERO_ERROR', - self::U_PARSE_ERROR => 'Number parsing failed: U_PARSE_ERROR', - ); - /** * The error code from the last operation * * @var integer */ - protected $errorCode = self::U_ZERO_ERROR; + protected $errorCode = StubIntl::U_ZERO_ERROR; + + /** + * The error message from the last operation + * + * @var string + */ + protected $errorMessage = 'U_ZERO_ERROR'; /** Format style constants */ const PATTERN_DECIMAL = 0; @@ -403,7 +390,7 @@ class StubNumberFormatter */ public function getErrorMessage() { - return $this->errorMessages[$this->errorCode]; + return $this->errorMessage; } /** @@ -514,7 +501,9 @@ class StubNumberFormatter // Any string before the numeric value causes error in the parsing if (isset($matches[1]) && !empty($matches[1])) { - $this->errorCode = self::U_PARSE_ERROR; + StubIntl::setErrorCode(StubIntl::U_PARSE_ERROR); + $this->errorCode = StubIntl::getErrorCode(); + $this->errorMessage = StubIntl::getErrorMessage(); return false; } diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php index 8d545c1d20..f681e3260e 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php @@ -63,6 +63,9 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->assertSame($errorMessage, StubIntl::getErrorMessage()); $this->assertSame($errorCode, StubIntl::getErrorCode()); $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode())); + $this->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); } /** @@ -482,13 +485,13 @@ class StubIntlDateFormatterTest extends LocaleTestCase public function testGetErrorCode() { $formatter = $this->createStubFormatter(); - $this->assertEquals(StubIntlDateFormatter::U_ZERO_ERROR, $formatter->getErrorCode()); + $this->assertEquals(StubIntl::getErrorCode(), $formatter->getErrorCode()); } public function testGetErrorMessage() { $formatter = $this->createStubFormatter(); - $this->assertEquals(StubIntlDateFormatter::U_ZERO_ERROR_MESSAGE, $formatter->getErrorMessage()); + $this->assertEquals(StubIntl::getErrorMessage(), $formatter->getErrorMessage()); } public function testGetLocale() @@ -556,6 +559,9 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->assertSame($errorMessage, StubIntl::getErrorMessage()); $this->assertSame($errorCode, StubIntl::getErrorCode()); $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode())); + $this->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); } public function parseProvider() @@ -711,7 +717,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->skipIfIntlExtensionIsNotLoaded(); $formatter = $this->createIntlFormatter($pattern); - $this->assertSame(false, $formatter->parse($value)); + $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())); @@ -726,10 +732,13 @@ class StubIntlDateFormatterTest extends LocaleTestCase $errorMessage = 'Date parsing failed: U_PARSE_ERROR'; $formatter = $this->createStubFormatter($pattern); - $this->assertSame(false, $formatter->parse($value)); + $this->assertFalse($formatter->parse($value)); $this->assertSame($errorMessage, StubIntl::getErrorMessage()); $this->assertSame($errorCode, StubIntl::getErrorCode()); $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode())); + $this->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); } public function parseErrorProvider() diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php index a3261717ee..7535e28c23 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php @@ -14,6 +14,7 @@ namespace Symfony\Tests\Component\Locale\Stub; require_once __DIR__.'/../TestCase.php'; use Symfony\Component\Locale\Locale; +use Symfony\Component\Locale\Stub\StubIntl; use Symfony\Component\Locale\Stub\StubNumberFormatter; use Symfony\Tests\Component\Locale\TestCase as LocaleTestCase; @@ -613,7 +614,7 @@ class StubNumberFormatterTest extends LocaleTestCase public function testGetErrorCode() { $formatter = $this->getStubFormatterWithDecimalStyle(); - $this->assertEquals(StubNumberFormatter::U_ZERO_ERROR, $formatter->getErrorCode()); + $this->assertEquals(StubIntl::U_ZERO_ERROR, $formatter->getErrorCode()); } public function testGetLocale() @@ -668,9 +669,9 @@ class StubNumberFormatterTest extends LocaleTestCase $this->assertSame($expected, $parsedValue, $message); if ($expected === false) { - $this->assertSame($formatter::U_PARSE_ERROR, $formatter->getErrorCode()); + $this->assertSame(StubIntl::U_PARSE_ERROR, $formatter->getErrorCode()); } else { - $this->assertEquals($formatter::U_ZERO_ERROR, $formatter->getErrorCode()); + $this->assertEquals(StubIntl::U_ZERO_ERROR, $formatter->getErrorCode()); } } From 663d218e97a5b1d415804c48ea54ddcea948790d Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sat, 14 Apr 2012 17:15:57 -0300 Subject: [PATCH 04/14] [Locale] changed method name --- .../Component/Locale/Stub/DateFormat/FullTransformer.php | 4 ++-- src/Symfony/Component/Locale/Stub/StubIntl.php | 4 ++-- src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php | 2 +- src/Symfony/Component/Locale/Stub/StubNumberFormatter.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php b/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php index c13b1a330c..e06e0431ec 100644 --- a/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php +++ b/src/Symfony/Component/Locale/Stub/DateFormat/FullTransformer.php @@ -155,7 +155,7 @@ class FullTransformer } // behave like the intl extension - StubIntl::setErrorCode(StubIntl::U_PARSE_ERROR, 'Date parsing failed'); + StubIntl::setError(StubIntl::U_PARSE_ERROR, 'Date parsing failed'); return false; } @@ -292,7 +292,7 @@ class FullTransformer // If month is false, return immediately (intl behavior) if (false === $month) { - StubIntl::setErrorCode(StubIntl::U_PARSE_ERROR, 'Date parsing failed'); + StubIntl::setError(StubIntl::U_PARSE_ERROR, 'Date parsing failed'); return false; } diff --git a/src/Symfony/Component/Locale/Stub/StubIntl.php b/src/Symfony/Component/Locale/Stub/StubIntl.php index 509e1ee494..a036e15056 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntl.php +++ b/src/Symfony/Component/Locale/Stub/StubIntl.php @@ -102,14 +102,14 @@ abstract class StubIntl } /** - * Sets the current error code + * Sets the current error * * @param integer $code One of the error constants in this class * @param string $message The ICU class error message * * @throws \InvalidArgumentException If the code is not one of the error constants in this class */ - static public function setErrorCode($code, $message = '') + static public function setError($code, $message = '') { if (!isset(self::$errorCodes[$code])) { throw new \InvalidArgumentException(sprintf('No such error code: "%s"', $code)); diff --git a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php index 10392c052d..5b68291260 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php @@ -180,7 +180,7 @@ class StubIntlDateFormatter // behave like the intl extension if (!is_int($timestamp) && version_compare(\PHP_VERSION, '5.3.4', '<')) { - StubIntl::setErrorCode(StubIntl::U_ILLEGAL_ARGUMENT_ERROR); + StubIntl::setError(StubIntl::U_ILLEGAL_ARGUMENT_ERROR, 'datefmt_format: takes either an array or an integer timestamp value '); return false; } diff --git a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php index ad72c2183d..73719d6293 100644 --- a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php @@ -501,7 +501,7 @@ class StubNumberFormatter // Any string before the numeric value causes error in the parsing if (isset($matches[1]) && !empty($matches[1])) { - StubIntl::setErrorCode(StubIntl::U_PARSE_ERROR); + StubIntl::setError(StubIntl::U_PARSE_ERROR); $this->errorCode = StubIntl::getErrorCode(); $this->errorMessage = StubIntl::getErrorMessage(); From b1ea5524488db93bfecbcf08910908813e0ae3c7 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sat, 14 Apr 2012 16:55:51 -0300 Subject: [PATCH 05/14] [Locale] micro-optimization --- src/Symfony/Component/Locale/Stub/StubIntl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Locale/Stub/StubIntl.php b/src/Symfony/Component/Locale/Stub/StubIntl.php index a036e15056..1dfc731884 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntl.php +++ b/src/Symfony/Component/Locale/Stub/StubIntl.php @@ -73,7 +73,7 @@ abstract class StubIntl */ static public function isFailure($errorCode) { - return array_key_exists($errorCode, self::$errorCodes) + return isset(self::$errorCodes[$errorCode]) && $errorCode > self::U_ZERO_ERROR; } From 312a5a4201a7b0a192c0b47cc39145b5e6dfe071 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sun, 15 Apr 2012 14:56:41 -0300 Subject: [PATCH 06/14] [Locale] fixed StubIntlDateFormatter::format() to set the right error for PHP >= 5.3.4 and to behave like the intl when formatting successfully --- .../Locale/Stub/StubIntlDateFormatter.php | 17 ++++++++++- .../Locale/Stub/StubIntlDateFormatterTest.php | 29 ++++++++++++++----- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php index 5b68291260..5f0dfee698 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php @@ -179,8 +179,17 @@ class StubIntlDateFormatter } // behave like the intl extension + $argumentError = null; if (!is_int($timestamp) && version_compare(\PHP_VERSION, '5.3.4', '<')) { - StubIntl::setError(StubIntl::U_ILLEGAL_ARGUMENT_ERROR, 'datefmt_format: takes either an array or an integer timestamp value '); + $argumentError = 'datefmt_format: takes either an array or an integer timestamp value '; + } elseif (!is_int($timestamp) && !$timestamp instanceOf \DateTime && version_compare(\PHP_VERSION, '5.3.4', '>=')) { + $argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object'; + } + + if (null !== $argumentError) { + StubIntl::setError(StubIntl::U_ILLEGAL_ARGUMENT_ERROR, $argumentError); + $this->errorCode = StubIntl::getErrorCode(); + $this->errorMessage = StubIntl::getErrorMessage(); return false; } @@ -193,6 +202,11 @@ class StubIntlDateFormatter $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId()); $formatted = $transformer->format($this->createDateTime($timestamp)); + // behave like the intl extension + StubIntl::setError(StubIntl::U_ZERO_ERROR); + $this->errorCode = StubIntl::getErrorCode(); + $this->errorMessage = StubIntl::getErrorMessage(); + return $formatted; } @@ -359,6 +373,7 @@ class StubIntlDateFormatter $timestamp = $transformer->parse($dateTime, $value); + // behave like the intl extension. FullTransformer::parse() set the proper error if (false === $timestamp) { $this->errorCode = StubIntl::getErrorCode(); $this->errorMessage = StubIntl::getErrorMessage(); diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php index f681e3260e..636b20fa83 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php @@ -82,6 +82,21 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->assertSame($errorCode != 0, intl_is_failure(intl_get_error_code())); } + /** + * @dataProvider formatErrorProvider + */ + public function testFormatErrorStub($pattern, $timestamp, $expected, $errorCode = 0, $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->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); + } + /** * @dataProvider formatErrorProvider */ @@ -90,10 +105,6 @@ class StubIntlDateFormatterTest extends LocaleTestCase $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.'); - } - $formatter = $this->createIntlFormatter($pattern); $this->assertSame($expected, $formatter->format($timestamp)); $this->assertSame($errorMessage, intl_get_error_message()); @@ -297,11 +308,15 @@ class StubIntlDateFormatterTest extends LocaleTestCase public function formatErrorProvider() { - /* errors */ + $message = 'datefmt_format: takes either an array or an integer timestamp value : U_ILLEGAL_ARGUMENT_ERROR'; + + if (version_compare(\PHP_VERSION, '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', false, 1, $message), + array('y-M-d', 'foobar', false, 1, $message), ); } From e4769d937766ef5d2b23e6c11e8368d3cea38bcb Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sun, 15 Apr 2012 14:57:23 -0300 Subject: [PATCH 07/14] [Locale] reordered test methods --- .../Locale/Stub/StubIntlDateFormatterTest.php | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php index 636b20fa83..6e9eec3345 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php @@ -82,36 +82,6 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->assertSame($errorCode != 0, intl_is_failure(intl_get_error_code())); } - /** - * @dataProvider formatErrorProvider - */ - public function testFormatErrorStub($pattern, $timestamp, $expected, $errorCode = 0, $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->assertSame($errorMessage, $formatter->getErrorMessage()); - $this->assertSame($errorCode, $formatter->getErrorCode()); - $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); - } - - /** - * @dataProvider formatErrorProvider - */ - public function testFormatErrorIntl($pattern, $timestamp, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR') - { - $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())); - } - public function formatProvider() { $formatData = array( @@ -306,6 +276,36 @@ class StubIntlDateFormatterTest extends LocaleTestCase return $formatData; } + /** + * @dataProvider formatErrorProvider + */ + public function testFormatErrorStub($pattern, $timestamp, $expected, $errorCode = 0, $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->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); + } + + /** + * @dataProvider formatErrorProvider + */ + public function testFormatErrorIntl($pattern, $timestamp, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR') + { + $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())); + } + public function formatErrorProvider() { $message = 'datefmt_format: takes either an array or an integer timestamp value : U_ILLEGAL_ARGUMENT_ERROR'; From 6f9c05d4f9824298f8e608d093f1512b8c8ac9d4 Mon Sep 17 00:00:00 2001 From: stealth35 Date: Mon, 16 Apr 2012 13:30:41 +0200 Subject: [PATCH 08/14] [Locale] Complete Stub with intl_error_name --- .../Locale/Resources/stubs/functions.php | 11 +++++ .../Component/Locale/Stub/StubIntl.php | 14 ++++++ .../Component/Locale/Stub/StubIntlTest.php | 47 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php diff --git a/src/Symfony/Component/Locale/Resources/stubs/functions.php b/src/Symfony/Component/Locale/Resources/stubs/functions.php index 100f6fb99d..2444c3735a 100644 --- a/src/Symfony/Component/Locale/Resources/stubs/functions.php +++ b/src/Symfony/Component/Locale/Resources/stubs/functions.php @@ -45,3 +45,14 @@ function intl_get_error_code() { function intl_get_error_message() { return StubIntl::getErrorMessage(); } + +/** + * Stub implementation for the intl_error_name function of the intl extension + * + * @return String will be the same as the name of the error code constant + * + * @see Symfony\Component\Locale\Stub\StubIntl::getErrorName + */ +function intl_error_name($errorCode) { + return StubIntl::getErrorName($errorCode); +} \ No newline at end of file diff --git a/src/Symfony/Component/Locale/Stub/StubIntl.php b/src/Symfony/Component/Locale/Stub/StubIntl.php index 1dfc731884..8c8648027b 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntl.php +++ b/src/Symfony/Component/Locale/Stub/StubIntl.php @@ -101,6 +101,20 @@ abstract class StubIntl return self::$errorMessage; } + /** + * Returns the symbolic name for a given error code + * + * @return string + */ + static public function getErrorName($code) + { + if (isset(self::$errorCodes[$code])) { + return self::$errorCodes[$code]; + } + + return '[BOGUS UErrorCode]'; + } + /** * Sets the current error * diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php new file mode 100644 index 0000000000..b26eb46a0b --- /dev/null +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\Locale\Stub; + +require_once __DIR__.'/../TestCase.php'; + +use Symfony\Component\Locale\Locale; +use Symfony\Component\Locale\Stub\StubIntl; +use Symfony\Tests\Component\Locale\TestCase as LocaleTestCase; + +class StubIntlTest extends LocaleTestCase +{ + public function codeProvider() + { + return array ( + array(0, 'U_ZERO_ERROR'), + array(1, 'U_ILLEGAL_ARGUMENT_ERROR'), + array(9, 'U_PARSE_ERROR'), + ); + } + + /** + * @dataProvider codeProvider + */ + public function testGetErrorName($code, $name) + { + $this->assertSame($name, StubIntl::getErrorName($code)); + } + + /** + * @dataProvider codeProvider + */ + public function testGetErrorNameWithIntl($code, $name) + { + $this->skipIfIntlExtensionIsNotLoaded(); + $this->assertSame(intl_error_name($code), StubIntl::getErrorName($code)); + } +} From 5799d2532468ac6d58bcf6ac3f9b2cc18556d6e6 Mon Sep 17 00:00:00 2001 From: stealth35 Date: Mon, 16 Apr 2012 13:33:13 +0200 Subject: [PATCH 09/14] Add BOGUS UErrorCode test --- tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php index b26eb46a0b..a8c8e07094 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlTest.php @@ -22,9 +22,11 @@ class StubIntlTest extends LocaleTestCase public function codeProvider() { return array ( + array(-129, '[BOGUS UErrorCode]'), array(0, 'U_ZERO_ERROR'), array(1, 'U_ILLEGAL_ARGUMENT_ERROR'), array(9, 'U_PARSE_ERROR'), + array(129, '[BOGUS UErrorCode]'), ); } From 0a606642b77573e493c808c12c2d2568166bb510 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sun, 15 Apr 2012 15:32:40 -0300 Subject: [PATCH 10/14] [Locale] updated StubIntlDateFormatter::format() exception message when timestamp argument is an array for PHP >= 5.3.4 --- .../Locale/Stub/StubIntlDateFormatter.php | 12 ++++--- .../Locale/Stub/StubIntlDateFormatterTest.php | 33 +++++++++++++++++-- .../Tests/Component/Locale/TestCase.php | 5 +++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php index 5f0dfee698..ec339043a1 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php @@ -175,14 +175,18 @@ class StubIntlDateFormatter { // intl allows timestamps to be passed as arrays - we don't if (is_array($timestamp)) { - throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, 'Only integer unix timestamps are supported'); + $message = version_compare(\PHP_VERSION, '5.3.4', '>=') ? + 'Only integer unix timestamps and DateTime objects are supported' : + 'Only integer unix timestamps are supported'; + + throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, $message); } // behave like the intl extension $argumentError = null; - if (!is_int($timestamp) && version_compare(\PHP_VERSION, '5.3.4', '<')) { + if (version_compare(\PHP_VERSION, '5.3.4', '<') && !is_int($timestamp)) { $argumentError = 'datefmt_format: takes either an array or an integer timestamp value '; - } elseif (!is_int($timestamp) && !$timestamp instanceOf \DateTime && version_compare(\PHP_VERSION, '5.3.4', '>=')) { + } elseif (version_compare(\PHP_VERSION, '5.3.4', '>=') && !is_int($timestamp) && !$timestamp instanceOf \DateTime) { $argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object'; } @@ -195,7 +199,7 @@ class StubIntlDateFormatter } // As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances - if ($timestamp instanceOf \DateTime && version_compare(\PHP_VERSION, '5.3.4', '>=')) { + if (version_compare(\PHP_VERSION, '5.3.4', '>=') && $timestamp instanceOf \DateTime) { $timestamp = $timestamp->getTimestamp(); } diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php index 6e9eec3345..4317a18830 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php @@ -53,6 +53,35 @@ 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 */ @@ -261,7 +290,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 */ @@ -310,7 +339,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase { $message = 'datefmt_format: takes either an array or an integer timestamp value : U_ILLEGAL_ARGUMENT_ERROR'; - if (version_compare(\PHP_VERSION, '5.3.4', '>=')) { + 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'; } diff --git a/tests/Symfony/Tests/Component/Locale/TestCase.php b/tests/Symfony/Tests/Component/Locale/TestCase.php index 0d6661fb49..8df87e447b 100644 --- a/tests/Symfony/Tests/Component/Locale/TestCase.php +++ b/tests/Symfony/Tests/Component/Locale/TestCase.php @@ -58,6 +58,11 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase } } + protected function isGreaterOrEqualThanPhpVersion($version) + { + return version_compare(\PHP_VERSION, $version, '>='); + } + protected function isGreaterOrEqualThanIcuVersion($version) { $version = $this->normalizeIcuVersion($version); From f16ff892bb12fab4e06f410ca7c8ffb02bef7ecb Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sun, 15 Apr 2012 19:08:47 -0300 Subject: [PATCH 11/14] [Locale] fixed StubNumberFormatter::parse() to behave like the NumberFormatter::parse() regarding to error flagging --- .../Locale/Stub/StubNumberFormatter.php | 10 +++++-- .../Locale/Stub/StubNumberFormatterTest.php | 27 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php index 73719d6293..a3a0412094 100644 --- a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php @@ -501,7 +501,7 @@ class StubNumberFormatter // Any string before the numeric value causes error in the parsing if (isset($matches[1]) && !empty($matches[1])) { - StubIntl::setError(StubIntl::U_PARSE_ERROR); + StubIntl::setError(StubIntl::U_PARSE_ERROR, 'Number parsing failed'); $this->errorCode = StubIntl::getErrorCode(); $this->errorMessage = StubIntl::getErrorMessage(); @@ -510,8 +510,14 @@ class StubNumberFormatter // Remove everything that is not number or dot (.) $value = preg_replace('/[^0-9\.\-]/', '', $value); + $value = $this->convertValueDataType($value, $type); - return $this->convertValueDataType($value, $type); + // behave like the intl extension + StubIntl::setError(StubIntl::U_ZERO_ERROR); + $this->errorCode = StubIntl::getErrorCode(); + $this->errorMessage = StubIntl::getErrorMessage(); + + return $value; } /** diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php index 7535e28c23..000d736af7 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php @@ -669,10 +669,19 @@ class StubNumberFormatterTest extends LocaleTestCase $this->assertSame($expected, $parsedValue, $message); if ($expected === false) { - $this->assertSame(StubIntl::U_PARSE_ERROR, $formatter->getErrorCode()); + $errorCode = StubIntl::U_PARSE_ERROR; + $errorMessage = 'Number parsing failed: U_PARSE_ERROR'; } else { - $this->assertEquals(StubIntl::U_ZERO_ERROR, $formatter->getErrorCode()); + $errorCode = StubIntl::U_ZERO_ERROR; + $errorMessage = 'U_ZERO_ERROR'; } + + $this->assertSame($errorMessage, StubIntl::getErrorMessage()); + $this->assertSame($errorCode, StubIntl::getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode())); + $this->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); } /** @@ -682,15 +691,25 @@ class StubNumberFormatterTest extends LocaleTestCase { $this->skipIfIntlExtensionIsNotLoaded(); $this->skipIfICUVersionIsTooOld(); + $formatter = $this->getIntlFormatterWithDecimalStyle(); $parsedValue = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE); $this->assertSame($expected, $parsedValue, $message); if ($expected === false) { - $this->assertSame(U_PARSE_ERROR, $formatter->getErrorCode()); + $errorCode = StubIntl::U_PARSE_ERROR; + $errorMessage = 'Number parsing failed: U_PARSE_ERROR'; } else { - $this->assertEquals(U_ZERO_ERROR, $formatter->getErrorCode()); + $errorCode = StubIntl::U_ZERO_ERROR; + $errorMessage = 'U_ZERO_ERROR'; } + + $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->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, intl_is_failure($formatter->getErrorCode())); } public function parseProvider() From e4cbbf3e8c9d423d25b2693743bdf9e4b8dfa424 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sun, 15 Apr 2012 19:28:47 -0300 Subject: [PATCH 12/14] [Locale] fixed StubNumberFormatter::format() to behave like the NumberFormatter::parse() regarding to error flagging --- .../Locale/Stub/StubNumberFormatter.php | 8 ++++++- .../Locale/Stub/StubNumberFormatterTest.php | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php index a3a0412094..c4949d062c 100644 --- a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php @@ -351,8 +351,14 @@ class StubNumberFormatter $fractionDigits = $this->getAttribute(self::FRACTION_DIGITS); $value = $this->round($value, $fractionDigits); + $value = $this->formatNumber($value, $fractionDigits); - return $this->formatNumber($value, $fractionDigits); + // behave like the intl extension + StubIntl::setError(StubIntl::U_ZERO_ERROR); + $this->errorCode = StubIntl::getErrorCode(); + $this->errorMessage = StubIntl::getErrorMessage(); + + return $value; } /** diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php index 000d736af7..1236598ab7 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php @@ -225,15 +225,36 @@ class StubNumberFormatterTest extends LocaleTestCase public function testFormatStub() { + $errorCode = StubIntl::U_ZERO_ERROR; + $errorMessage = 'U_ZERO_ERROR'; + $formatter = $this->getStubFormatterWithDecimalStyle(); $this->assertSame('9.555', $formatter->format(9.555)); + + $this->assertSame($errorMessage, StubIntl::getErrorMessage()); + $this->assertSame($errorCode, StubIntl::getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode())); + $this->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); } public function testFormatIntl() { $this->skipIfIntlExtensionIsNotLoaded(); + + $errorCode = StubIntl::U_ZERO_ERROR; + $errorMessage = 'U_ZERO_ERROR'; + $formatter = $this->getIntlFormatterWithDecimalStyle(); $this->assertSame('9.555', $formatter->format(9.555)); + + $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->assertSame($errorMessage, $formatter->getErrorMessage()); + $this->assertSame($errorCode, $formatter->getErrorCode()); + $this->assertSame($errorCode != 0, intl_is_failure($formatter->getErrorCode())); } /** From 09d30d3d1e980b0b9804bdb8f237d705b4c581a3 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sun, 15 Apr 2012 20:01:42 -0300 Subject: [PATCH 13/14] [Locale] refactored some code --- .../Component/Locale/Stub/StubCollator.php | 14 +--- .../Locale/Stub/StubNumberFormatter.php | 66 ++++++++++--------- .../Locale/Stub/StubCollatorTest.php | 5 +- .../Locale/Stub/StubIntlDateFormatterTest.php | 27 +++++--- 4 files changed, 60 insertions(+), 52 deletions(-) diff --git a/src/Symfony/Component/Locale/Stub/StubCollator.php b/src/Symfony/Component/Locale/Stub/StubCollator.php index a6bd4ddb7d..73b1d76096 100644 --- a/src/Symfony/Component/Locale/Stub/StubCollator.php +++ b/src/Symfony/Component/Locale/Stub/StubCollator.php @@ -21,16 +21,6 @@ use Symfony\Component\Locale\Exception\MethodArgumentValueNotImplementedExceptio */ class StubCollator { - /** - * Constants defined by the intl extension, not class constants in IntlDateFormatter - * TODO: remove if the Form component drop the call to the intl_is_failure() function - * - * @see StubIntlDateFormatter::getErrorCode() - * @see StubIntlDateFormatter::getErrorMessage() - */ - const U_ZERO_ERROR = 0; - const U_ZERO_ERROR_MESSAGE = 'U_ZERO_ERROR'; - /** Attribute constants */ const FRENCH_COLLATION = 0; const ALTERNATE_HANDLING = 1; @@ -158,7 +148,7 @@ class StubCollator */ public function getErrorCode() { - return self::U_ZERO_ERROR; + return StubIntl::U_ZERO_ERROR; } /** @@ -168,7 +158,7 @@ class StubCollator */ public function getErrorMessage() { - return self::U_ZERO_ERROR_MESSAGE; + return 'U_ZERO_ERROR'; } /** diff --git a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php index c4949d062c..08df95e173 100644 --- a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php @@ -24,20 +24,6 @@ use Symfony\Component\Locale\Exception\MethodArgumentValueNotImplementedExceptio */ class StubNumberFormatter { - /** - * The error code from the last operation - * - * @var integer - */ - protected $errorCode = StubIntl::U_ZERO_ERROR; - - /** - * The error message from the last operation - * - * @var string - */ - protected $errorMessage = 'U_ZERO_ERROR'; - /** Format style constants */ const PATTERN_DECIMAL = 0; const DECIMAL = 1; @@ -125,6 +111,30 @@ class StubNumberFormatter const PAD_BEFORE_SUFFIX = 2; const PAD_AFTER_SUFFIX = 3; + /** + * The error code from the last operation + * + * @var integer + */ + protected $errorCode = StubIntl::U_ZERO_ERROR; + + /** + * The error message from the last operation + * + * @var string + */ + protected $errorMessage = 'U_ZERO_ERROR'; + + /** + * @var string + */ + private $locale; + + /** + * @var int + */ + private $style; + /** * Default values for the en locale * @@ -211,16 +221,6 @@ class StubNumberFormatter 'negative' => -9223372036854775808 ); - /** - * @var string - */ - private $locale = null; - - /** - * @var int - */ - private $style = null; - /** * Constructor * @@ -354,9 +354,7 @@ class StubNumberFormatter $value = $this->formatNumber($value, $fractionDigits); // behave like the intl extension - StubIntl::setError(StubIntl::U_ZERO_ERROR); - $this->errorCode = StubIntl::getErrorCode(); - $this->errorMessage = StubIntl::getErrorMessage(); + $this->resetError(); return $value; } @@ -519,9 +517,7 @@ class StubNumberFormatter $value = $this->convertValueDataType($value, $type); // behave like the intl extension - StubIntl::setError(StubIntl::U_ZERO_ERROR); - $this->errorCode = StubIntl::getErrorCode(); - $this->errorMessage = StubIntl::getErrorMessage(); + $this->resetError(); return $value; } @@ -624,6 +620,16 @@ class StubNumberFormatter throw new MethodNotImplementedException(__METHOD__); } + /** + * Set the error to the default U_ZERO_ERROR + */ + protected function resetError() + { + StubIntl::setError(StubIntl::U_ZERO_ERROR); + $this->errorCode = StubIntl::getErrorCode(); + $this->errorMessage = StubIntl::getErrorMessage(); + } + /** * Rounds a currency value, applying increment rounding if applicable * diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubCollatorTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubCollatorTest.php index f65da5d180..397b2732ca 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubCollatorTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubCollatorTest.php @@ -15,6 +15,7 @@ require_once __DIR__.'/../TestCase.php'; use Symfony\Component\Locale\Locale; use Symfony\Component\Locale\Stub\StubCollator; +use Symfony\Component\Locale\Stub\StubIntl; use Symfony\Tests\Component\Locale\TestCase as LocaleTestCase; class StubCollatorTest extends LocaleTestCase @@ -91,13 +92,13 @@ class StubCollatorTest extends LocaleTestCase public function testGetErrorCode() { $collator = $this->createStubCollator(); - $this->assertEquals(StubCollator::U_ZERO_ERROR, $collator->getErrorCode()); + $this->assertEquals(StubIntl::U_ZERO_ERROR, $collator->getErrorCode()); } public function testGetErrorMessage() { $collator = $this->createStubCollator(); - $this->assertEquals(StubCollator::U_ZERO_ERROR_MESSAGE, $collator->getErrorMessage()); + $this->assertEquals('U_ZERO_ERROR', $collator->getErrorMessage()); } public function testGetLocale() diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php index 4317a18830..2beb388e93 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php @@ -85,8 +85,11 @@ class StubIntlDateFormatterTest extends LocaleTestCase /** * @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()); @@ -100,10 +103,14 @@ class StubIntlDateFormatterTest extends LocaleTestCase /** * @dataProvider formatProvider */ - public function testFormatIntl($pattern, $timestamp, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR') + public function testFormatIntl($pattern, $timestamp, $expected) { $this->skipIfIntlExtensionIsNotLoaded(); $this->skipIfICUVersionIsTooOld(); + + $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()); @@ -308,10 +315,12 @@ class StubIntlDateFormatterTest extends LocaleTestCase /** * @dataProvider formatErrorProvider */ - public function testFormatErrorStub($pattern, $timestamp, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR') + public function testFormatIllegalArgumentErrorStub($pattern, $timestamp, $errorMessage) { + $errorCode = StubIntl::U_ILLEGAL_ARGUMENT_ERROR; + $formatter = $this->createStubFormatter($pattern); - $this->assertSame($expected, $formatter->format($timestamp)); + $this->assertFalse($formatter->format($timestamp)); $this->assertSame($errorMessage, StubIntl::getErrorMessage()); $this->assertSame($errorCode, StubIntl::getErrorCode()); $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode())); @@ -323,13 +332,15 @@ class StubIntlDateFormatterTest extends LocaleTestCase /** * @dataProvider formatErrorProvider */ - public function testFormatErrorIntl($pattern, $timestamp, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR') + public function testFormatIllegalArgumentErrorIntl($pattern, $timestamp, $errorMessage) { $this->skipIfIntlExtensionIsNotLoaded(); $this->skipIfICUVersionIsTooOld(); + $errorCode = StubIntl::U_ILLEGAL_ARGUMENT_ERROR; + $formatter = $this->createIntlFormatter($pattern); - $this->assertSame($expected, $formatter->format($timestamp)); + $this->assertFalse($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())); @@ -344,8 +355,8 @@ class StubIntlDateFormatterTest extends LocaleTestCase } return array( - array('y-M-d', '0', false, 1, $message), - array('y-M-d', 'foobar', false, 1, $message), + array('y-M-d', '0', $message), + array('y-M-d', 'foobar', $message), ); } From fab1b5ac8f258b01b7a3c339c9494815b7757002 Mon Sep 17 00:00:00 2001 From: Eriksen Costa Date: Sun, 15 Apr 2012 20:23:02 -0300 Subject: [PATCH 14/14] [Locale] changed inequality operator to strict checking and updated some assertions --- ...odArgumentValueNotImplementedException.php | 2 +- .../Stub/DateFormat/TimeZoneTransformer.php | 2 +- .../Locale/Stub/StubIntlDateFormatter.php | 4 ++-- .../Component/Locale/Stub/StubLocale.php | 2 +- .../Locale/Stub/StubIntlDateFormatterTest.php | 24 +++++++++---------- .../Locale/Stub/StubNumberFormatterTest.php | 16 ++++++------- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Symfony/Component/Locale/Exception/MethodArgumentValueNotImplementedException.php b/src/Symfony/Component/Locale/Exception/MethodArgumentValueNotImplementedException.php index 770f4181f6..2fdb6feaed 100644 --- a/src/Symfony/Component/Locale/Exception/MethodArgumentValueNotImplementedException.php +++ b/src/Symfony/Component/Locale/Exception/MethodArgumentValueNotImplementedException.php @@ -33,7 +33,7 @@ class MethodArgumentValueNotImplementedException extends NotImplementedException $methodName, $argName, var_export($argValue, true), - $additionalMessage != '' ? ' '.$additionalMessage.'. ' : '' + $additionalMessage !== '' ? ' '.$additionalMessage.'. ' : '' ); parent::__construct($message); diff --git a/src/Symfony/Component/Locale/Stub/DateFormat/TimeZoneTransformer.php b/src/Symfony/Component/Locale/Stub/DateFormat/TimeZoneTransformer.php index d48e0a84b4..f817ba0d21 100644 --- a/src/Symfony/Component/Locale/Stub/DateFormat/TimeZoneTransformer.php +++ b/src/Symfony/Component/Locale/Stub/DateFormat/TimeZoneTransformer.php @@ -88,7 +88,7 @@ class TimeZoneTransformer extends Transformer )); } - return 'Etc/GMT'.($hours != 0 ? $signal.$hours : ''); + return 'Etc/GMT'.($hours !== 0 ? $signal.$hours : ''); } throw new \InvalidArgumentException('The GMT time zone \'%s\' does not match with the supported formats GMT[+-]HH:MM or GMT[+-]HHMM.'); diff --git a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php index ec339043a1..ca21c9e82c 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php @@ -124,11 +124,11 @@ class StubIntlDateFormatter */ public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null) { - if ('en' != $locale) { + if ('en' !== $locale) { throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the \'en\' locale is supported'); } - if (self::GREGORIAN != $calendar) { + if (self::GREGORIAN !== $calendar) { throw new MethodArgumentValueNotImplementedException(__METHOD__, 'calendar', $calendar, 'Only the GREGORIAN calendar is supported'); } diff --git a/src/Symfony/Component/Locale/Stub/StubLocale.php b/src/Symfony/Component/Locale/Stub/StubLocale.php index f4c3852e6d..831960f21b 100644 --- a/src/Symfony/Component/Locale/Stub/StubLocale.php +++ b/src/Symfony/Component/Locale/Stub/StubLocale.php @@ -480,7 +480,7 @@ class StubLocale */ static private function getStubData($locale, $cacheVariable, $stubDataDir) { - if ('en' != $locale) { + if ('en' !== $locale) { throw new \InvalidArgumentException(sprintf('Only the \'en\' locale is supported. %s', NotImplementedException::INTL_INSTALL_MESSAGE)); } diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php index 2beb388e93..79bcd5299c 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php @@ -94,10 +94,10 @@ class StubIntlDateFormatterTest extends LocaleTestCase $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())); } /** @@ -115,7 +115,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase $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() @@ -323,10 +323,10 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->assertFalse($formatter->format($timestamp)); $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())); } /** @@ -343,7 +343,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->assertFalse($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->assertTrue(intl_is_failure(intl_get_error_code())); } public function formatErrorProvider() @@ -598,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())); } /** @@ -613,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() @@ -775,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())); } /** @@ -790,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() diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php index 1236598ab7..e775763aee 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php @@ -233,10 +233,10 @@ class StubNumberFormatterTest extends LocaleTestCase $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 testFormatIntl() @@ -251,10 +251,10 @@ class StubNumberFormatterTest extends LocaleTestCase $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())); $this->assertSame($errorMessage, $formatter->getErrorMessage()); $this->assertSame($errorCode, $formatter->getErrorCode()); - $this->assertSame($errorCode != 0, intl_is_failure($formatter->getErrorCode())); + $this->assertFalse(intl_is_failure($formatter->getErrorCode())); } /** @@ -699,10 +699,10 @@ class StubNumberFormatterTest extends LocaleTestCase $this->assertSame($errorMessage, StubIntl::getErrorMessage()); $this->assertSame($errorCode, StubIntl::getErrorCode()); - $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode())); + $this->assertSame($errorCode !== 0, StubIntl::isFailure(StubIntl::getErrorCode())); $this->assertSame($errorMessage, $formatter->getErrorMessage()); $this->assertSame($errorCode, $formatter->getErrorCode()); - $this->assertSame($errorCode != 0, StubIntl::isFailure($formatter->getErrorCode())); + $this->assertSame($errorCode !== 0, StubIntl::isFailure($formatter->getErrorCode())); } /** @@ -727,10 +727,10 @@ class StubNumberFormatterTest extends LocaleTestCase $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->assertSame($errorCode > 0, intl_is_failure(intl_get_error_code())); $this->assertSame($errorMessage, $formatter->getErrorMessage()); $this->assertSame($errorCode, $formatter->getErrorCode()); - $this->assertSame($errorCode != 0, intl_is_failure($formatter->getErrorCode())); + $this->assertSame($errorCode > 0, intl_is_failure($formatter->getErrorCode())); } public function parseProvider()