From 37e1f1a94393b712fa735e23aab2021477b3de50 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 1 Sep 2015 12:10:08 +0200 Subject: [PATCH] [3.0] Fix tests --- .travis.yml | 1 - .../Bridge/Twig/Tests/Node/TransNodeTest.php | 2 +- .../Debug/Tests/ErrorHandlerTest.php | 11 ++++----- .../Intl/DateFormatter/IntlDateFormatter.php | 5 +--- .../Intl/NumberFormatter/NumberFormatter.php | 4 ++++ .../Bundle/Reader/IntlBundleReaderTest.php | 8 ------- .../Bundle/Writer/PhpBundleWriterTest.php | 4 ---- .../AbstractIntlDateFormatterTest.php | 23 ------------------- .../Verification/IntlDateFormatterTest.php | 13 ----------- .../AbstractNumberFormatterTest.php | 2 -- .../AbstractComparisonValidatorTestCase.php | 4 ---- .../NotIdenticalToValidatorTest.php | 3 --- 12 files changed, 11 insertions(+), 69 deletions(-) diff --git a/.travis.yml b/.travis.yml index 90eebdb528..42c1e5cec7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ addons: matrix: include: - php: hhvm - - php: 5.5.9 - php: 5.5 - php: 5.6 - php: 5.6 diff --git a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php index 5628518f90..2281444e97 100644 --- a/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php @@ -47,6 +47,6 @@ class TransNodeTest extends \PHPUnit_Framework_TestCase return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : $this->notFound("%s", 0))', $name, $name, $name, $name); } - return sprintf('$this->getContext($context, "%s")', $name); + return sprintf('(isset($context["%1$s"]) ? $context["%1$s"] : $this->getContext($context, "%1$s"))', $name); } } diff --git a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php index 3a7e2cbf60..741044aff5 100644 --- a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php @@ -295,12 +295,11 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase public function testHandleDeprecation() { - $that = $this; - $logArgCheck = function ($level, $message, $context) use ($that) { - $that->assertEquals(LogLevel::INFO, $level); - $that->assertArrayHasKey('level', $context); - $that->assertEquals(E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED, $context['level']); - $that->assertArrayHasKey('stack', $context); + $logArgCheck = function ($level, $message, $context) { + $this->assertEquals(LogLevel::INFO, $level); + $this->assertArrayHasKey('level', $context); + $this->assertEquals(E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED, $context['level']); + $this->assertArrayHasKey('stack', $context); }; $logger = $this->getMock('Psr\Log\LoggerInterface'); diff --git a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php index 39016c5c00..d68e5c82d3 100644 --- a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php +++ b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php @@ -207,10 +207,7 @@ class IntlDateFormatter // behave like the intl extension $argumentError = null; if (!is_int($timestamp) && !$timestamp instanceof \DateTime) { - $argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object'; - if (!is_int($timestamp)) { - $argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp); - } + $argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp); } if (null !== $argumentError) { diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index 08367811f9..67b389cca2 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -857,6 +857,10 @@ class NumberFormatter return false; } + if (PHP_INT_SIZE !== 8 && ($value > self::$int32Range['positive'] || $value < self::$int32Range['negative'])) { + return (float) $value; + } + return (int) $value; } diff --git a/src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/IntlBundleReaderTest.php b/src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/IntlBundleReaderTest.php index f7284c3d7c..4875f8cbd3 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/IntlBundleReaderTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/IntlBundleReaderTest.php @@ -55,10 +55,6 @@ class IntlBundleReaderTest extends \PHPUnit_Framework_TestCase public function testReadDoesNotFollowFallback() { - if (PHP_VERSION_ID < 50307 || PHP_VERSION_ID === 50400) { - $this->markTestSkipped('ResourceBundle handles disabling fallback properly only as of PHP 5.3.7 and 5.4.1.'); - } - if (defined('HHVM_VERSION')) { $this->markTestSkipped('ResourceBundle does not support disabling fallback properly on HHVM.'); } @@ -75,10 +71,6 @@ class IntlBundleReaderTest extends \PHPUnit_Framework_TestCase public function testReadDoesNotFollowFallbackAlias() { - if (PHP_VERSION_ID < 50307 || PHP_VERSION_ID === 50400) { - $this->markTestSkipped('ResourceBundle handles disabling fallback properly only as of PHP 5.3.7 and 5.4.1.'); - } - if (defined('HHVM_VERSION')) { $this->markTestSkipped('ResourceBundle does not support disabling fallback properly on HHVM.'); } diff --git a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php index efc3519e3a..2eb76075d9 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/PhpBundleWriterTest.php @@ -71,10 +71,6 @@ class PhpBundleWriterTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('The intl extension is not available.'); } - if (PHP_VERSION_ID < 50315 || (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50404)) { - $this->markTestSkipped('ResourceBundle implements Traversable only as of PHP 5.3.15 and 5.4.4'); - } - $bundle = new \ResourceBundle('rb', __DIR__.'/Fixtures', false); $this->writer->write($this->directory, 'en', $bundle); diff --git a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php index 66e0cd8ced..b24a3f676c 100644 --- a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php @@ -306,10 +306,6 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase array(0, 'Europe/Dublin', '1970-01-01 01:00:00'), array(0, 'Europe/Warsaw', '1970-01-01 01:00:00'), array(0, 'Pacific/Fiji', '1970-01-01 12:00:00'), - array(0, 'Foo/Bar', '1970-01-01 00:00:00'), - array(0, 'Foo/Bar', '1970-01-01 00:00:00'), - array(0, 'UTC+04:30', '1970-01-01 00:00:00'), - array(0, 'UTC+04:AA', '1970-01-01 00:00:00'), ); return $data; @@ -382,25 +378,6 @@ abstract class AbstractIntlDateFormatterTest extends \PHPUnit_Framework_TestCase $this->assertEquals('GMT+03:00', $formatter->format(0)); } - public function testFormatWithTimezoneFromEnvironmentVariable() - { - $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() { $tz = date_default_timezone_get(); diff --git a/src/Symfony/Component/Intl/Tests/DateFormatter/Verification/IntlDateFormatterTest.php b/src/Symfony/Component/Intl/Tests/DateFormatter/Verification/IntlDateFormatterTest.php index dcf38473f2..7eca02e207 100644 --- a/src/Symfony/Component/Intl/Tests/DateFormatter/Verification/IntlDateFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/DateFormatter/Verification/IntlDateFormatterTest.php @@ -30,19 +30,6 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest parent::setUp(); } - /** - * 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. - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testFormatWithTimezoneFromEnvironmentVariable() - { - parent::testFormatWithTimezoneFromEnvironmentVariable(); - } - protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null) { if (!$formatter = new \IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern)) { diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php index 0663c28166..21ebca46c7 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php @@ -683,9 +683,7 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase $this->assertEquals(2147483647, $parsedValue); $parsedValue = $formatter->parse('-2,147,483,648', NumberFormatter::TYPE_INT64); - $this->assertInternalType('int', $parsedValue); - $this->assertEquals(-2147483648, $parsedValue); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index 6bfb7b7797..dab59aa57f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -125,10 +125,6 @@ abstract class AbstractComparisonValidatorTestCase extends AbstractConstraintVal // Make sure we have the correct version loaded if ($dirtyValue instanceof \DateTime || $dirtyValue instanceof \DateTimeInterface) { IntlTestHelper::requireIntl($this); - - if (PHP_VERSION_ID < 50304 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) { - $this->markTestSkipped('Intl supports formatting DateTime objects since 5.3.4'); - } } $constraint = $this->createConstraint(array('value' => $comparedValue)); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php index 68dddeb290..3810a847f4 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php @@ -87,9 +87,6 @@ class NotIdenticalToValidatorTest extends AbstractComparisonValidatorTestCase array($object, '2', $object, '2', __NAMESPACE__.'\ComparisonTest_Class'), ); - $immutableDate = new \DateTimeImmutable('2000-01-01'); - $comparisons[] = array($immutableDate, 'Jan 1, 2000, 12:00 AM', $immutableDate, 'Jan 1, 2000, 12:00 AM', 'DateTime'); - return $comparisons; } }