Merge branch '5.1'

* 5.1:
  [ErrorHandler] Return false directly and remove unused variable
  [OptionsResolver] Assert that the error type is valid in deprecations test
  [OptionsResolver] Fix deprecation message access
  [HttpClient] Allow bearer token with colon
  [Form] Fix custom formats deprecation with HTML5 widgets
  [Translator] Optional Intl dependency
  [Contracts][Translation] Optional Intl dependency
  [ErrorHandler] Escape JSON encoded log context
  update missing translations arabic
  [Yaml] simplify the test
  fix test by letting mock throw the actual expected exception
This commit is contained in:
Fabien Potencier 2020-09-27 05:44:38 +02:00
commit 6ca92258d7
13 changed files with 56 additions and 32 deletions

View File

@ -425,9 +425,8 @@ class ErrorHandler
}
if (!$type || (!$log && !$throw)) {
return !$silenced && $type && $log;
return false;
}
$scope = $this->scopedErrors & $type;
if (false !== strpos($message, "@anonymous\0")) {
$logMessage = $this->parseAnonymousClass($message);

View File

@ -35,7 +35,7 @@
<td>
<?= $this->formatLogMessage($log['message'], $log['context']); ?>
<?php if ($log['context']) { ?>
<pre class="text-muted prewrap m-t-5"><?= json_encode($log['context'], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES); ?></pre>
<pre class="text-muted prewrap m-t-5"><?= $this->escape(json_encode($log['context'], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES)); ?></pre>
<?php } ?>
</td>
</tr>

View File

@ -26,6 +26,7 @@ use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\ReversedTransformer;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -343,13 +344,22 @@ class DateTimeType extends AbstractType
return $timeWidget;
});
$resolver->setNormalizer('html5', function (Options $options, $html5) {
if ($html5 && self::HTML5_FORMAT !== $options['format']) {
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
}
foreach (['html5', 'format'] as $option) {
$resolver->setDeprecated($option, static function (Options $options, $value) use ($option): string {
try {
$html5 = 'html5' === $option ? $value : $options['html5'];
$format = 'format' === $option ? $value : $options['format'];
} catch (OptionDefinitionException $e) {
return '';
}
return $html5;
});
if ($html5 && self::HTML5_FORMAT !== $format) {
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
}
return $html5;
});
}
}
/**

View File

@ -23,6 +23,7 @@ use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\ReversedTransformer;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -328,13 +329,23 @@ class DateType extends AbstractType
$resolver->setAllowedTypes('days', 'array');
$resolver->setAllowedTypes('input_format', 'string');
$resolver->setNormalizer('html5', function (Options $options, $html5) {
if ($html5 && 'single_text' === $options['widget'] && self::HTML5_FORMAT !== $options['format']) {
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
}
foreach (['html5', 'widget', 'format'] as $option) {
$resolver->setDeprecated($option, static function (Options $options, $value) use ($option): string {
try {
$html5 = 'html5' === $option ? $value : $options['html5'];
$widget = 'widget' === $option ? $value : $options['widget'];
$format = 'format' === $option ? $value : $options['format'];
} catch (OptionDefinitionException $e) {
return '';
}
return $html5;
});
if ($html5 && 'single_text' === $widget && self::HTML5_FORMAT !== $format) {
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
}
return $html5;
});
}
}
/**

View File

@ -520,6 +520,7 @@ class DateTimeTypeTest extends BaseTypeTest
'widget' => 'single_text',
'date_format' => \IntlDateFormatter::SHORT,
'format' => null,
'html5' => false,
]);
$view = $form->createView();

View File

@ -111,7 +111,7 @@ trait HttpClientTrait
throw new InvalidArgumentException(sprintf('Option "auth_basic" must be string or an array, "%s" given.', get_debug_type($options['auth_basic'])));
}
if (isset($options['auth_bearer']) && (!\is_string($options['auth_bearer']) || !preg_match('{^[-._=~+/0-9a-zA-Z]++$}', $options['auth_bearer']))) {
if (isset($options['auth_bearer']) && (!\is_string($options['auth_bearer']) || !preg_match('{^[-._=:~+/0-9a-zA-Z]++$}', $options['auth_bearer']))) {
throw new InvalidArgumentException(sprintf('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, %s given.', \is_string($options['auth_bearer']) ? 'invalid string' : '"'.get_debug_type($options['auth_bearer']).'"'));
}

View File

@ -144,7 +144,10 @@ class BundleEntryReaderTest extends TestCase
[self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
)
->willReturnOnConsecutiveCalls(self::$data, self::$fallbackData);
->willReturnOnConsecutiveCalls(
$this->throwException(new ResourceBundleNotFoundException()),
self::$fallbackData
);
$this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
}
@ -283,7 +286,7 @@ class BundleEntryReaderTest extends TestCase
[self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
)
->willReturnOnConsecutiveCalls(['Foo' => 'Baz'], ['Foo' => 'Baz']);
->willReturnOnConsecutiveCalls(['Foo' => 'Baz'], ['Foo' => 'Bar']);
$this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true);
}

View File

@ -1079,7 +1079,7 @@ class OptionsResolver implements Options
// Check whether the option is deprecated
// and it is provided by the user or is being called from a lazy evaluation
if ($triggerDeprecation && isset($this->deprecated[$option]) && (isset($this->given[$option]) || ($this->calling && \is_string($this->deprecated[$option])))) {
if ($triggerDeprecation && isset($this->deprecated[$option]) && (isset($this->given[$option]) || ($this->calling && \is_string($this->deprecated[$option]['message'])))) {
$deprecation = $this->deprecated[$option];
$message = $this->deprecated[$option]['message'];

View File

@ -524,7 +524,9 @@ class OptionsResolverTest extends TestCase
{
$count = 0;
error_clear_last();
set_error_handler(function () use (&$count) {
set_error_handler(function (int $type) use (&$count) {
$this->assertSame(\E_USER_DEPRECATED, $type);
++$count;
return false;

View File

@ -150,7 +150,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
public function setLocale(string $locale)
{
$this->assertValidLocale($locale);
$this->locale = $locale;
$this->locale = $locale ?? (class_exists(\Locale::class) ? \Locale::getDefault() : 'en');
}
/**
@ -158,7 +158,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
*/
public function getLocale()
{
return $this->locale ?? \Locale::getDefault();
return $this->locale;
}
/**

View File

@ -382,6 +382,10 @@
<source>Each element of this collection should satisfy its own set of constraints.</source>
<target>يجب أن يفي كل عنصر من عناصر هذه المجموعة بمجموعة القيود الخاصة به.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
<target> صالح (ISIN) هذه القيمة ليست رقم تعريف الأوراق المالية الدولي.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -2456,19 +2456,13 @@ a:
c: d
YAML;
$expected = ['a' => ['b' => "row\nrow2\n"], 'c' => 'd'];
// The parser was not used before, so there is a new line after row2
$this->assertSame($expected, $this->parser->parse($longDocument));
$parser = new Parser();
// The first parsing set and fixed the totalNumberOfLines in the Parser before, so parsing the short document here
// to reproduce the issue. If the issue would not have been fixed, the next assertion will fail
$parser->parse($shortDocument);
$this->parser->parse($shortDocument);
// After the total number of lines has been rset the result will be the same as if a new parser was used
// After the total number of lines has been reset the result will be the same as if a new parser was used
// (before, there was no \n after row2)
$this->assertSame($expected, $parser->parse($longDocument));
$this->assertSame(['a' => ['b' => "row\nrow2\n"], 'c' => 'd'], $this->parser->parse($longDocument));
}
}

View File

@ -35,7 +35,7 @@ trait TranslatorTrait
*/
public function getLocale()
{
return $this->locale ?: \Locale::getDefault();
return $this->locale ?: (class_exists(\Locale::class) ? \Locale::getDefault() : 'en');
}
/**