From 05ec8a08b40280760853aaec69ef25f6a95fc56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 6 Aug 2019 11:10:43 +0200 Subject: [PATCH] Fix remaining tests --- .../DependencyInjection/Configuration.php | 2 +- src/Symfony/Component/Config/Util/XmlUtils.php | 2 +- src/Symfony/Component/Debug/ErrorHandler.php | 2 +- .../Component/Debug/Tests/ErrorHandlerTest.php | 4 ++++ .../Component/DomCrawler/FormFieldRegistry.php | 4 ++-- .../Tests/Iterator/SortableIteratorTest.php | 6 +----- .../Tests/Extension/Core/Type/DateTypeTest.php | 10 ++++++---- .../AbstractCurrencyDataProviderTest.php | 10 ++++++++++ .../AbstractLanguageDataProviderTest.php | 10 ++++++++++ .../Provider/AbstractLocaleDataProviderTest.php | 8 ++++++++ .../Provider/AbstractRegionDataProviderTest.php | 10 ++++++++++ .../Provider/AbstractScriptDataProviderTest.php | 10 ++++++++++ .../AbstractIntlDateFormatterTest.php | 12 ++++++++++++ src/Symfony/Component/Intl/Tests/IntlTest.php | 16 ++++++++++++++++ .../AbstractNumberFormatterTest.php | 2 +- .../Component/Stopwatch/Tests/StopwatchTest.php | 2 +- .../Translation/Loader/CsvFileLoader.php | 4 ++++ .../Translation/Tests/IdentityTranslatorTest.php | 16 ++++++++++++++++ .../Tests/Constraints/CountryValidatorTest.php | 16 ++++++++++++++++ .../Tests/Constraints/CurrencyValidatorTest.php | 16 ++++++++++++++++ .../Tests/Constraints/LanguageValidatorTest.php | 16 ++++++++++++++++ .../Tests/Constraints/RangeValidatorTest.php | 4 ++-- .../Tests/Caster/ExceptionCasterTest.php | 7 ++----- 23 files changed, 166 insertions(+), 23 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 52369bbffaa9..4dfbb0b82de9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -264,7 +264,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode) ->canBeEnabled() ->beforeNormalization() ->always(function ($v) { - if (true === $v['enabled']) { + if (\is_array($v) && true === $v['enabled']) { $workflows = $v; unset($workflows['enabled']); diff --git a/src/Symfony/Component/Config/Util/XmlUtils.php b/src/Symfony/Component/Config/Util/XmlUtils.php index df1edd68bd79..dfacaff4ea01 100644 --- a/src/Symfony/Component/Config/Util/XmlUtils.php +++ b/src/Symfony/Component/Config/Util/XmlUtils.php @@ -234,7 +234,7 @@ public static function phpize($value) return true; case 'false' === $lowercaseValue: return false; - case isset($value[1]) && '0b' == $value[0].$value[1]: + case isset($value[1]) && '0b' == $value[0].$value[1] && preg_match('/^0b[01]*$/', $value): return bindec($value); case is_numeric($value): return '0x' === $value[0].$value[1] ? hexdec($value) : (float) $value; diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index c7dc3279d73a..9d7c0c67ad6a 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -470,7 +470,7 @@ public function handleError($type, $message, $file, $line) } if ($throw) { - if (E_USER_ERROR & $type) { + if (\PHP_VERSION_ID < 70400 && E_USER_ERROR & $type) { for ($i = 1; isset($backtrace[$i]); ++$i) { if (isset($backtrace[$i]['function'], $backtrace[$i]['type'], $backtrace[$i - 1]['function']) && '__toString' === $backtrace[$i]['function'] diff --git a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php index 3094d22d95d9..2cf75a0e8e32 100644 --- a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php @@ -283,6 +283,10 @@ public function testHandleError() public function testHandleUserError() { + if (\PHP_VERSION_ID >= 70400) { + $this->markTestSkipped('PHP 7.4 allows __toString to throw exceptions'); + } + try { $handler = ErrorHandler::register(); $handler->throwAt(0, true); diff --git a/src/Symfony/Component/DomCrawler/FormFieldRegistry.php b/src/Symfony/Component/DomCrawler/FormFieldRegistry.php index 8f432cfbbb83..bd73742af743 100644 --- a/src/Symfony/Component/DomCrawler/FormFieldRegistry.php +++ b/src/Symfony/Component/DomCrawler/FormFieldRegistry.php @@ -57,7 +57,7 @@ public function remove($name) $target = &$this->fields; while (\count($segments) > 1) { $path = array_shift($segments); - if (!\array_key_exists($path, $target)) { + if (!\is_array($target) || !\array_key_exists($path, $target)) { return; } $target = &$target[$path]; @@ -80,7 +80,7 @@ public function &get($name) $target = &$this->fields; while ($segments) { $path = array_shift($segments); - if (!\array_key_exists($path, $target)) { + if (!\is_array($target) || !\array_key_exists($path, $target)) { throw new \InvalidArgumentException(sprintf('Unreachable field "%s"', $path)); } $target = &$target[$path]; diff --git a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php index 57f1e096a533..118c4769f299 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php @@ -33,11 +33,7 @@ public function testAccept($mode, $expected) if (!\is_callable($mode)) { switch ($mode) { case SortableIterator::SORT_BY_ACCESSED_TIME: - if ('\\' === \DIRECTORY_SEPARATOR) { - touch(self::toAbsolute('.git')); - } else { - file_get_contents(self::toAbsolute('.git')); - } + touch(self::toAbsolute('.git')); sleep(1); file_get_contents(self::toAbsolute('.bar')); break; diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index 91e6ff5f8eb1..96c74fe0e420 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -471,6 +471,7 @@ public function testYearsOption() public function testMonthsOption() { + \Locale::setDefault('en'); $form = $this->factory->create(static::TESTED_TYPE, null, [ 'months' => [6, 7], 'format' => \IntlDateFormatter::SHORT, @@ -479,8 +480,8 @@ public function testMonthsOption() $view = $form->createView(); $this->assertEquals([ - new ChoiceView(6, '6', '06'), - new ChoiceView(7, '7', '07'), + new ChoiceView(6, '6', '6'), + new ChoiceView(7, '7', '7'), ], $view['month']->vars['choices']); } @@ -544,14 +545,15 @@ public function testMonthsOptionLongFormatWithDifferentTimezone() public function testIsDayWithinRangeReturnsTrueIfWithin() { + \Locale::setDefault('en'); $view = $this->factory->create(static::TESTED_TYPE, null, [ 'days' => [6, 7], ]) ->createView(); $this->assertEquals([ - new ChoiceView(6, '6', '06'), - new ChoiceView(7, '7', '07'), + new ChoiceView(6, '6', '6'), + new ChoiceView(7, '7', '7'), ], $view['day']->vars['choices']); } diff --git a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractCurrencyDataProviderTest.php b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractCurrencyDataProviderTest.php index 3b1f4957aa7a..12660eb0acfb 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractCurrencyDataProviderTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractCurrencyDataProviderTest.php @@ -589,6 +589,7 @@ abstract class AbstractCurrencyDataProviderTest extends AbstractDataProviderTest * @var CurrencyDataProvider */ protected $dataProvider; + private $defaultLocale; protected function setUp() { @@ -598,6 +599,15 @@ protected function setUp() $this->getDataDirectory().'/'.Intl::CURRENCY_DIR, $this->createEntryReader() ); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); } abstract protected function getDataDirectory(); diff --git a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLanguageDataProviderTest.php b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLanguageDataProviderTest.php index 917f6f0dd1e6..2d294f2c6429 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLanguageDataProviderTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLanguageDataProviderTest.php @@ -831,6 +831,7 @@ abstract class AbstractLanguageDataProviderTest extends AbstractDataProviderTest * @var LanguageDataProvider */ protected $dataProvider; + private $defaultLocale; protected function setUp() { @@ -840,6 +841,15 @@ protected function setUp() $this->getDataDirectory().'/'.Intl::LANGUAGE_DIR, $this->createEntryReader() ); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); } abstract protected function getDataDirectory(); diff --git a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLocaleDataProviderTest.php b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLocaleDataProviderTest.php index 88242a6f9bcb..7da43c70eb85 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLocaleDataProviderTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLocaleDataProviderTest.php @@ -23,6 +23,7 @@ abstract class AbstractLocaleDataProviderTest extends AbstractDataProviderTest * @var LocaleDataProvider */ protected $dataProvider; + private $defaultLocale; protected function setUp() { @@ -32,6 +33,13 @@ protected function setUp() $this->getDataDirectory().'/'.Intl::LOCALE_DIR, $this->createEntryReader() ); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + \Locale::setDefault($this->defaultLocale); } abstract protected function getDataDirectory(); diff --git a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractRegionDataProviderTest.php b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractRegionDataProviderTest.php index aeb922f9e3e5..6e2f57aa7a51 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractRegionDataProviderTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractRegionDataProviderTest.php @@ -283,6 +283,7 @@ abstract class AbstractRegionDataProviderTest extends AbstractDataProviderTest * @var RegionDataProvider */ protected $dataProvider; + private $defaultLocale; protected function setUp() { @@ -292,6 +293,15 @@ protected function setUp() $this->getDataDirectory().'/'.Intl::REGION_DIR, $this->createEntryReader() ); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); } abstract protected function getDataDirectory(); diff --git a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractScriptDataProviderTest.php b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractScriptDataProviderTest.php index 8620fb2060fb..5c279065a192 100644 --- a/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractScriptDataProviderTest.php +++ b/src/Symfony/Component/Intl/Tests/Data/Provider/AbstractScriptDataProviderTest.php @@ -219,6 +219,7 @@ abstract class AbstractScriptDataProviderTest extends AbstractDataProviderTest * @var ScriptDataProvider */ protected $dataProvider; + private $defaultLocale; protected function setUp() { @@ -228,6 +229,15 @@ protected function setUp() $this->getDataDirectory().'/'.Intl::SCRIPT_DIR, $this->createEntryReader() ); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); } abstract protected function getDataDirectory(); diff --git a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php index 682380bf5415..df99b1210939 100644 --- a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php @@ -24,11 +24,23 @@ */ abstract class AbstractIntlDateFormatterTest extends TestCase { + private $defaultLocale; + protected function setUp() { + parent::setUp(); + + $this->defaultLocale = \Locale::getDefault(); \Locale::setDefault('en'); } + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); + } + /** * When a time zone is not specified, it uses the system default however it returns null in the getter method. * diff --git a/src/Symfony/Component/Intl/Tests/IntlTest.php b/src/Symfony/Component/Intl/Tests/IntlTest.php index d45a1ded5c30..059f5eb6c4a4 100644 --- a/src/Symfony/Component/Intl/Tests/IntlTest.php +++ b/src/Symfony/Component/Intl/Tests/IntlTest.php @@ -16,6 +16,22 @@ class IntlTest extends TestCase { + private $defaultLocale; + + protected function setUp() + { + parent::setUp(); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); + } + /** * @requires extension intl */ diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php index 9e8499eba963..f64131a61b8c 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php @@ -36,7 +36,7 @@ public function formatCurrencyWithDecimalStyleProvider() { return [ [100, 'ALL', '100'], - [100, 'BRL', '100.00'], + [100, 'BRL', '100'], [100, 'CRC', '100'], [100, 'JPY', '100'], [100, 'CHF', '100'], diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php index f85ccd0ec442..b8efa373b4cd 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php @@ -87,7 +87,7 @@ public function testStop() $event = $stopwatch->stop('foo'); $this->assertInstanceOf('Symfony\Component\Stopwatch\StopwatchEvent', $event); - $this->assertEquals(200, $event->getDuration(), '', self::DELTA); + $this->assertEqualsWithDelta(200, $event->getDuration(), self::DELTA); } public function testUnknownEvent() diff --git a/src/Symfony/Component/Translation/Loader/CsvFileLoader.php b/src/Symfony/Component/Translation/Loader/CsvFileLoader.php index 18cc83ed686c..db17bd563111 100644 --- a/src/Symfony/Component/Translation/Loader/CsvFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/CsvFileLoader.php @@ -41,6 +41,10 @@ protected function loadResource($resource) $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape); foreach ($file as $data) { + if (false === $data) { + continue; + } + if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === \count($data)) { $messages[$data[0]] = $data[1]; } diff --git a/src/Symfony/Component/Translation/Tests/IdentityTranslatorTest.php b/src/Symfony/Component/Translation/Tests/IdentityTranslatorTest.php index c3d7b1f7d128..a5c63df98847 100644 --- a/src/Symfony/Component/Translation/Tests/IdentityTranslatorTest.php +++ b/src/Symfony/Component/Translation/Tests/IdentityTranslatorTest.php @@ -17,6 +17,22 @@ class IdentityTranslatorTest extends TestCase { + private $defaultLocale; + + protected function setUp() + { + parent::setUp(); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); + } + /** * @dataProvider getTransTests */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php index 429aef812f0d..f5cb9a6db38f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php @@ -18,6 +18,22 @@ class CountryValidatorTest extends ConstraintValidatorTestCase { + private $defaultLocale; + + protected function setUp() + { + parent::setUp(); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); + } + protected function createValidator() { return new CountryValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php index 7a619735369e..d46fcd55487e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php @@ -18,6 +18,22 @@ class CurrencyValidatorTest extends ConstraintValidatorTestCase { + private $defaultLocale; + + protected function setUp() + { + parent::setUp(); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); + } + protected function createValidator() { return new CurrencyValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php index f23fd13fcb69..31a987bdd3e5 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php @@ -18,6 +18,22 @@ class LanguageValidatorTest extends ConstraintValidatorTestCase { + private $defaultLocale; + + protected function setUp() + { + parent::setUp(); + + $this->defaultLocale = \Locale::getDefault(); + } + + protected function tearDown() + { + parent::tearDown(); + + \Locale::setDefault($this->defaultLocale); + } + protected function createValidator() { return new LanguageValidator(); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php index 661161d886a2..df33d2c422f9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php @@ -50,7 +50,7 @@ public function getLessThanTen() [9.99999, '9.99999'], ['9.99999', '"9.99999"'], [5, '5'], - [1.0, '1.0'], + [1.0, '1'], ]; } @@ -60,7 +60,7 @@ public function getMoreThanTwenty() [20.000001, '20.000001'], ['20.000001', '"20.000001"'], [21, '21'], - [30.0, '30.0'], + [30.0, '30'], ]; } diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php index ea83e77163d1..738180f5b22d 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php @@ -52,7 +52,6 @@ public function testDefaultSettings() › } } %s%eTests%eCaster%eExceptionCasterTest.php:40 { …} - Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->testDefaultSettings() {} %A EODUMP; @@ -71,8 +70,7 @@ public function testSeek() › return new \Exception(''.$msg); › } } - %s%eTests%eCaster%eExceptionCasterTest.php:65 { …} - Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->testSeek() {} + %s%eTests%eCaster%eExceptionCasterTest.php:64 { …} %A EODUMP; @@ -96,8 +94,7 @@ public function testNoArgs() › return new \Exception(''.$msg); › } } - %s%eTests%eCaster%eExceptionCasterTest.php:84 { …} - Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->testNoArgs() {} + %s%eTests%eCaster%eExceptionCasterTest.php:82 { …} %A EODUMP;