Fix remaining tests

This commit is contained in:
Jérémy Derussé 2019-08-06 11:10:43 +02:00
parent 87c8561c00
commit 05ec8a08b4
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2
23 changed files with 166 additions and 23 deletions

View File

@ -264,7 +264,7 @@ class Configuration implements ConfigurationInterface
->canBeEnabled()
->beforeNormalization()
->always(function ($v) {
if (true === $v['enabled']) {
if (\is_array($v) && true === $v['enabled']) {
$workflows = $v;
unset($workflows['enabled']);

View File

@ -234,7 +234,7 @@ class XmlUtils
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;

View File

@ -470,7 +470,7 @@ class ErrorHandler
}
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']

View File

@ -283,6 +283,10 @@ class ErrorHandlerTest extends TestCase
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);

View File

@ -57,7 +57,7 @@ class FormFieldRegistry
$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 @@ class FormFieldRegistry
$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];

View File

@ -33,11 +33,7 @@ class SortableIteratorTest extends RealIteratorTestCase
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;

View File

@ -471,6 +471,7 @@ class DateTypeTest extends BaseTypeTest
public function testMonthsOption()
{
\Locale::setDefault('en');
$form = $this->factory->create(static::TESTED_TYPE, null, [
'months' => [6, 7],
'format' => \IntlDateFormatter::SHORT,
@ -479,8 +480,8 @@ class DateTypeTest extends BaseTypeTest
$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 @@ class DateTypeTest extends BaseTypeTest
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']);
}

View File

@ -589,6 +589,7 @@ abstract class AbstractCurrencyDataProviderTest extends AbstractDataProviderTest
* @var CurrencyDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
@ -598,6 +599,15 @@ abstract class AbstractCurrencyDataProviderTest extends AbstractDataProviderTest
$this->getDataDirectory().'/'.Intl::CURRENCY_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();

View File

@ -831,6 +831,7 @@ abstract class AbstractLanguageDataProviderTest extends AbstractDataProviderTest
* @var LanguageDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
@ -840,6 +841,15 @@ abstract class AbstractLanguageDataProviderTest extends AbstractDataProviderTest
$this->getDataDirectory().'/'.Intl::LANGUAGE_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();

View File

@ -23,6 +23,7 @@ abstract class AbstractLocaleDataProviderTest extends AbstractDataProviderTest
* @var LocaleDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
@ -32,6 +33,13 @@ abstract class AbstractLocaleDataProviderTest extends AbstractDataProviderTest
$this->getDataDirectory().'/'.Intl::LOCALE_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();

View File

@ -283,6 +283,7 @@ abstract class AbstractRegionDataProviderTest extends AbstractDataProviderTest
* @var RegionDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
@ -292,6 +293,15 @@ abstract class AbstractRegionDataProviderTest extends AbstractDataProviderTest
$this->getDataDirectory().'/'.Intl::REGION_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();

View File

@ -219,6 +219,7 @@ abstract class AbstractScriptDataProviderTest extends AbstractDataProviderTest
* @var ScriptDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
@ -228,6 +229,15 @@ abstract class AbstractScriptDataProviderTest extends AbstractDataProviderTest
$this->getDataDirectory().'/'.Intl::SCRIPT_DIR,
$this->createEntryReader()
);
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
abstract protected function getDataDirectory();

View File

@ -24,11 +24,23 @@ use Symfony\Component\Intl\Util\IcuVersion;
*/
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.
*

View File

@ -16,6 +16,22 @@ use Symfony\Component\Intl\Intl;
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
*/

View File

@ -36,7 +36,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
{
return [
[100, 'ALL', '100'],
[100, 'BRL', '100.00'],
[100, 'BRL', '100'],
[100, 'CRC', '100'],
[100, 'JPY', '100'],
[100, 'CHF', '100'],

View File

@ -87,7 +87,7 @@ class StopwatchTest extends TestCase
$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()

View File

@ -41,6 +41,10 @@ class CsvFileLoader extends FileLoader
$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];
}

View File

@ -17,6 +17,22 @@ use Symfony\Component\Translation\IdentityTranslator;
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
*/

View File

@ -18,6 +18,22 @@ use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
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();

View File

@ -18,6 +18,22 @@ use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
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();

View File

@ -18,6 +18,22 @@ use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
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();

View File

@ -50,7 +50,7 @@ class RangeValidatorTest extends ConstraintValidatorTestCase
[9.99999, '9.99999'],
['9.99999', '"9.99999"'],
[5, '5'],
[1.0, '1.0'],
[1.0, '1'],
];
}
@ -60,7 +60,7 @@ class RangeValidatorTest extends ConstraintValidatorTestCase
[20.000001, '20.000001'],
['20.000001', '"20.000001"'],
[21, '21'],
[30.0, '30.0'],
[30.0, '30'],
];
}

View File

@ -52,7 +52,6 @@ Exception {
}
}
%s%eTests%eCaster%eExceptionCasterTest.php:40 { }
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->testDefaultSettings() {}
%A
EODUMP;
@ -71,8 +70,7 @@ EODUMP;
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 @@ Exception {
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;