Skip to content

Commit

Permalink
Fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Aug 6, 2019
1 parent 87c8561 commit 914c8b7
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 20 deletions.
Expand Up @@ -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']);

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -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']
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -478,9 +478,11 @@ public function testMonthsOption()

$view = $form->createView();

\Locale::setDefault('en');

$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']);
}

Expand Down Expand Up @@ -549,9 +551,11 @@ public function testIsDayWithinRangeReturnsTrueIfWithin()
])
->createView();

\Locale::setDefault('en');

$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']);
}

Expand Down
Expand Up @@ -589,6 +589,7 @@ abstract class AbstractCurrencyDataProviderTest extends AbstractDataProviderTest
* @var CurrencyDataProvider
*/
protected $dataProvider;
private $defaultLocale;

protected function setUp()
{
Expand All @@ -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();
Expand Down
Expand Up @@ -831,6 +831,7 @@ abstract class AbstractLanguageDataProviderTest extends AbstractDataProviderTest
* @var LanguageDataProvider
*/
protected $dataProvider;
private $defaultLocale;

protected function setUp()
{
Expand All @@ -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();
Expand Down
Expand Up @@ -23,6 +23,7 @@ abstract class AbstractLocaleDataProviderTest extends AbstractDataProviderTest
* @var LocaleDataProvider
*/
protected $dataProvider;
private $defaultLocale;

protected function setUp()
{
Expand All @@ -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();
Expand Down
Expand Up @@ -283,6 +283,7 @@ abstract class AbstractRegionDataProviderTest extends AbstractDataProviderTest
* @var RegionDataProvider
*/
protected $dataProvider;
private $defaultLocale;

protected function setUp()
{
Expand All @@ -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();
Expand Down
Expand Up @@ -219,6 +219,7 @@ abstract class AbstractScriptDataProviderTest extends AbstractDataProviderTest
* @var ScriptDataProvider
*/
protected $dataProvider;
private $defaultLocale;

protected function setUp()
{
Expand All @@ -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();
Expand Down
Expand Up @@ -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.
*
Expand Down
16 changes: 16 additions & 0 deletions src/Symfony/Component/Intl/Tests/IntlTest.php
Expand Up @@ -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
*/
Expand Down
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Translation/Loader/CsvFileLoader.php
Expand Up @@ -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];
}
Expand Down
16 changes: 16 additions & 0 deletions src/Symfony/Component/Translation/Tests/IdentityTranslatorTest.php
Expand Up @@ -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
*/
Expand Down
Expand Up @@ -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();
Expand Down
Expand Up @@ -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();
Expand Down
Expand Up @@ -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();
Expand Down
Expand Up @@ -50,7 +50,7 @@ public function getLessThanTen()
[9.99999, '9.99999'],
['9.99999', '"9.99999"'],
[5, '5'],
[1.0, '1.0'],
[1.0, '1'],
];
}

Expand All @@ -60,7 +60,7 @@ public function getMoreThanTwenty()
[20.000001, '20.000001'],
['20.000001', '"20.000001"'],
[21, '21'],
[30.0, '30.0'],
[30.0, '30'],
];
}

Expand Down

0 comments on commit 914c8b7

Please sign in to comment.