Merge branch '3.4' into 4.3

* 3.4:
  Fix inconsistent return points.
  Fix remaining tests
This commit is contained in:
Nicolas Grekas 2019-08-07 13:52:19 +02:00
commit 381c995d30
32 changed files with 220 additions and 60 deletions

View File

@ -113,5 +113,7 @@ class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface
return $handler;
}
}
return null;
}
}

View File

@ -225,7 +225,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

@ -54,14 +54,14 @@ class FirewallMap implements FirewallMapInterface
$context = $this->getFirewallContext($request);
if (null === $context) {
return;
return null;
}
return $context->getConfig();
}
/**
* @return FirewallContext
* @return FirewallContext|null
*/
private function getFirewallContext(Request $request)
{
@ -83,5 +83,7 @@ class FirewallMap implements FirewallMapInterface
return $this->container->get($contextId);
}
}
return null;
}
}

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

@ -87,25 +87,13 @@ class Terminal
*/
private static function getConsoleMode()
{
if (!\function_exists('proc_open')) {
return;
$info = self::readFromProcess('mode CON');
if (null === $info || !preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
return null;
}
$descriptorspec = [
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
$process = proc_open('mode CON', $descriptorspec, $pipes, null, null, ['suppress_errors' => true]);
if (\is_resource($process)) {
$info = stream_get_contents($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
return [(int) $matches[2], (int) $matches[1]];
}
}
return [(int) $matches[2], (int) $matches[1]];
}
/**
@ -114,9 +102,19 @@ class Terminal
* @return string|null
*/
private static function getSttyColumns()
{
return self::readFromProcess('stty -a | grep columns');
}
/**
* @param string $command
*
* @return string|null
*/
private static function readFromProcess($command)
{
if (!\function_exists('proc_open')) {
return;
return null;
}
$descriptorspec = [
@ -124,14 +122,16 @@ class Terminal
2 => ['pipe', 'w'],
];
$process = proc_open('stty -a | grep columns', $descriptorspec, $pipes, null, null, ['suppress_errors' => true]);
if (\is_resource($process)) {
$info = stream_get_contents($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
return $info;
$process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]);
if (!\is_resource($process)) {
return null;
}
$info = stream_get_contents($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
return $info;
}
}

View File

@ -459,7 +459,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

@ -309,6 +309,8 @@ class AutowirePass extends AbstractRecursivePass
if ($this->container->has($type) && !$this->container->findDefinition($type)->isAbstract()) {
return new TypedReference($type, $type, $reference->getInvalidBehavior());
}
return null;
}
/**
@ -441,7 +443,7 @@ class AutowirePass extends AbstractRecursivePass
} elseif (isset($this->types[$type])) {
$message = sprintf('the existing "%s" service', $this->types[$type]);
} else {
return;
return '';
}
return sprintf(' You should maybe alias this %s to %s.', class_exists($type, false) ? 'class' : 'interface', $message);
@ -470,5 +472,7 @@ class AutowirePass extends AbstractRecursivePass
if ($aliases) {
return sprintf('Try changing the type-hint%s to "%s" instead.', $extraContext, $aliases[0]);
}
return null;
}
}

View File

@ -230,7 +230,7 @@ class XmlFileLoader extends FileLoader
$alias->setDeprecated(true, $deprecated[0]->nodeValue ?: null);
}
return;
return null;
}
if ($this->isLoadingInstanceof) {

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

@ -507,6 +507,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,
@ -515,8 +516,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']);
}
@ -580,14 +581,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

@ -132,7 +132,7 @@ class Store implements StoreInterface
$key = $this->getCacheKey($request);
if (!$entries = $this->getMetadata($key)) {
return;
return null;
}
// find a cached entry that matches the request.
@ -146,7 +146,7 @@ class Store implements StoreInterface
}
if (null === $match) {
return;
return null;
}
$headers = $match[1];
@ -157,6 +157,7 @@ class Store implements StoreInterface
// TODO the metaStore referenced an entity that doesn't exist in
// the entityStore. We definitely want to return nil but we should
// also purge the entry from the meta-store when this is detected.
return null;
}
/**
@ -178,7 +179,7 @@ class Store implements StoreInterface
if (!$response->headers->has('X-Content-Digest')) {
$digest = $this->generateContentDigest($response);
if (false === $this->save($digest, $response->getContent())) {
if (!$this->save($digest, $response->getContent())) {
throw new \RuntimeException('Unable to store the entity.');
}
@ -207,7 +208,7 @@ class Store implements StoreInterface
array_unshift($entries, [$storedEnv, $headers]);
if (false === $this->save($key, serialize($entries))) {
if (!$this->save($key, serialize($entries))) {
throw new \RuntimeException('Unable to store the metadata.');
}
@ -246,7 +247,7 @@ class Store implements StoreInterface
}
}
if ($modified && false === $this->save($key, serialize($entries))) {
if ($modified && !$this->save($key, serialize($entries))) {
throw new \RuntimeException('Unable to store the metadata.');
}
}
@ -406,6 +407,8 @@ class Store implements StoreInterface
}
@chmod($path, 0666 & ~umask());
return true;
}
public function getPath($key)

View File

@ -591,6 +591,7 @@ abstract class AbstractCurrencyDataProviderTest extends AbstractDataProviderTest
* @var CurrencyDataProvider
*/
protected $dataProvider;
private $defaultLocale;
protected function setUp()
{
@ -600,6 +601,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

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

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

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

@ -762,6 +762,8 @@ class PropertyAccessor implements PropertyAccessorInterface
return [$addMethod, $removeMethod];
}
}
return null;
}
/**

View File

@ -337,7 +337,7 @@ class XmlFileLoader extends FileLoader
private function parseDefaultsConfig(\DOMElement $element, $path)
{
if ($this->isElementValueNull($element)) {
return;
return null;
}
// Check for existing element nodes in the default element. There can
@ -374,7 +374,7 @@ class XmlFileLoader extends FileLoader
private function parseDefaultNode(\DOMElement $node, $path)
{
if ($this->isElementValueNull($node)) {
return;
return null;
}
switch ($node->localName) {

View File

@ -250,6 +250,8 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
return $normalizer;
}
}
return null;
}
/**
@ -291,6 +293,8 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
return $normalizer;
}
}
return null;
}
/**

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

@ -16,6 +16,22 @@ use Symfony\Contracts\Translation\Test\TranslatorTest;
class IdentityTranslatorTest extends TranslatorTest
{
private $defaultLocale;
protected function setUp()
{
parent::setUp();
$this->defaultLocale = \Locale::getDefault();
}
protected function tearDown()
{
parent::tearDown();
\Locale::setDefault($this->defaultLocale);
}
public function getTranslator()
{
return new IdentityTranslator();

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;