Merge branch '4.4' into 5.1

* 4.4:
  Fix typo
  Fix deprecated libxml_disable_entity_loader
  Add Tagalog translations for validator messages 94, 95, 96 and 99
  PHPUnit's assertContains() performs strict comparisons now.
  [ClassLoader][Routing] Fix namespace parsing on php 8.
  Fix deprecated libxml_disable_entity_loader
  Made reference to PHPUnit\Util\XML::loadfile php5-compatible.
  [Validator] Add missing translations for german and vietnamese
  Modernized deprecated PHPUnit assertion calls
  [Console] The message of "class not found" errors has changed in php 8.
  The PHPUnit\Util\XML class has been removed in PHPUnit 9.3.
  [Console] Make sure we pass a numeric array of arguments to call_user_func_array().
  [Serializer] Fix that it will never reach DOMNode
  [Validator] sync translations
  [VarDumper] Improve previous fix on light array coloration
  [Cache] Fix #37667
This commit is contained in:
Fabien Potencier 2020-08-10 10:03:57 +02:00
commit c44c606b11
48 changed files with 279 additions and 147 deletions

View File

@ -127,7 +127,7 @@
"psr/http-client": "^1.0",
"psr/simple-cache": "^1.0",
"egulias/email-validator": "~1.2,>=1.2.8|~2.0",
"symfony/phpunit-bridge": "^5.0.8",
"symfony/phpunit-bridge": "^5.2",
"symfony/security-acl": "~2.8|~3.0",
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
"twig/cssinliner-extra": "^2.12",

View File

@ -43,7 +43,7 @@ class LintCommandTest extends TestCase
$ret = $tester->execute(['filename' => [$filename]], ['decorated' => false]);
$this->assertEquals(1, $ret, 'Returns 1 in case of error');
$this->assertRegExp('/ERROR in \S+ \(line /', trim($tester->getDisplay()));
$this->assertMatchesRegularExpression('/ERROR in \S+ \(line /', trim($tester->getDisplay()));
}
public function testLintFileNotReadable()
@ -64,7 +64,7 @@ class LintCommandTest extends TestCase
$ret = $tester->execute(['filename' => [$filename]], ['decorated' => false]);
$this->assertEquals(1, $ret, 'Returns 1 in case of error');
$this->assertRegExp('/ERROR in \S+ \(line /', trim($tester->getDisplay()));
$this->assertMatchesRegularExpression('/ERROR in \S+ \(line /', trim($tester->getDisplay()));
}
/**

View File

@ -81,6 +81,6 @@ class CacheClearCommandTest extends TestCase
$containerRef = new \ReflectionClass(require $containerFile);
$containerFile = str_replace('tes_'.\DIRECTORY_SEPARATOR, 'test'.\DIRECTORY_SEPARATOR, $containerRef->getFileName());
$this->assertRegExp(sprintf('/\'kernel.container_class\'\s*=>\s*\'%s\'/', $containerClass), file_get_contents($containerFile), 'kernel.container_class is properly set on the dumped container');
$this->assertMatchesRegularExpression(sprintf('/\'kernel.container_class\'\s*=>\s*\'%s\'/', $containerClass), file_get_contents($containerFile), 'kernel.container_class is properly set on the dumped container');
}
}

View File

@ -28,7 +28,7 @@ class TranslationDebugCommandTest extends TestCase
$tester = $this->createCommandTester(['foo' => 'foo']);
$res = $tester->execute(['locale' => 'en', 'bundle' => 'foo']);
$this->assertRegExp('/missing/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_MISSING, $res);
}
@ -37,7 +37,7 @@ class TranslationDebugCommandTest extends TestCase
$tester = $this->createCommandTester([], ['foo' => 'foo']);
$res = $tester->execute(['locale' => 'en', 'bundle' => 'foo']);
$this->assertRegExp('/unused/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_UNUSED, $res);
}
@ -46,7 +46,7 @@ class TranslationDebugCommandTest extends TestCase
$tester = $this->createCommandTester(['foo' => 'foo'], ['foo' => 'foo']);
$res = $tester->execute(['locale' => 'fr', 'bundle' => 'foo']);
$this->assertRegExp('/fallback/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/fallback/', $tester->getDisplay());
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_FALLBACK, $res);
}
@ -55,7 +55,7 @@ class TranslationDebugCommandTest extends TestCase
$tester = $this->createCommandTester();
$res = $tester->execute(['locale' => 'fr', 'bundle' => 'test']);
$this->assertRegExp('/No defined or extracted messages for locale "fr"/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/No defined or extracted messages for locale "fr"/', $tester->getDisplay());
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_GENERAL_ERROR, $res);
}
@ -65,8 +65,8 @@ class TranslationDebugCommandTest extends TestCase
$res = $tester->execute(['locale' => 'en']);
$expectedExitStatus = TranslationDebugCommand::EXIT_CODE_MISSING | TranslationDebugCommand::EXIT_CODE_UNUSED;
$this->assertRegExp('/missing/', $tester->getDisplay());
$this->assertRegExp('/unused/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
$this->assertEquals($expectedExitStatus, $res);
}
@ -83,8 +83,8 @@ class TranslationDebugCommandTest extends TestCase
$tester = $this->createCommandTester(['foo' => 'foo'], ['bar' => 'bar'], null, [$this->translationDir.'/trans'], [$this->translationDir.'/views']);
$res = $tester->execute(['locale' => 'en']);
$this->assertRegExp('/missing/', $tester->getDisplay());
$this->assertRegExp('/unused/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
$this->assertEquals($expectedExitStatus, $res);
}
@ -103,8 +103,8 @@ class TranslationDebugCommandTest extends TestCase
$tester = $this->createCommandTester(['foo' => 'foo'], ['bar' => 'bar'], $kernel);
$res = $tester->execute(['locale' => 'en', 'bundle' => $this->translationDir.'/customDir']);
$this->assertRegExp('/missing/', $tester->getDisplay());
$this->assertRegExp('/unused/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
$this->assertEquals($expectedExitStatus, $res);
}

View File

@ -28,8 +28,8 @@ class TranslationUpdateCommandTest extends TestCase
{
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]);
$this->assertRegExp('/foo/', $tester->getDisplay());
$this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
}
public function testDumpSortedMessagesAndClean()
@ -72,32 +72,32 @@ class TranslationUpdateCommandTest extends TestCase
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']], [], null, [$this->translationDir.'/trans'], [$this->translationDir.'/views']);
$tester->execute(['command' => 'translation:update', 'locale' => 'en', '--dump-messages' => true, '--clean' => true]);
$this->assertRegExp('/foo/', $tester->getDisplay());
$this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
}
public function testDumpTwoMessagesAndClean()
{
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'bar' => 'bar']]);
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true]);
$this->assertRegExp('/foo/', $tester->getDisplay());
$this->assertRegExp('/bar/', $tester->getDisplay());
$this->assertRegExp('/2 messages were successfully extracted/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/bar/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/2 messages were successfully extracted/', $tester->getDisplay());
}
public function testDumpMessagesForSpecificDomain()
{
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo'], 'mydomain' => ['bar' => 'bar']]);
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--domain' => 'mydomain']);
$this->assertRegExp('/bar/', $tester->getDisplay());
$this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/bar/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
}
public function testWriteMessages()
{
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true]);
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
}
public function testWriteMessagesInRootDirectory()
@ -109,14 +109,14 @@ class TranslationUpdateCommandTest extends TestCase
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
$tester->execute(['command' => 'translation:update', 'locale' => 'en', '--force' => true]);
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
}
public function testWriteMessagesForSpecificDomain()
{
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo'], 'mydomain' => ['bar' => 'bar']]);
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--force' => true, '--domain' => 'mydomain']);
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
}
protected function setUp(): void

View File

@ -20,7 +20,7 @@ class IconTest extends TestCase
*/
public function testIconFileContents($iconFilePath)
{
$this->assertRegExp('~<svg xmlns="http://www.w3.org/2000/svg" width="\d+" height="\d+" viewBox="0 0 \d+ \d+">.*</svg>~s', file_get_contents($iconFilePath), sprintf('The SVG metadata of the %s icon is different than expected (use the same as the other icons).', $iconFilePath));
$this->assertMatchesRegularExpression('~<svg xmlns="http://www.w3.org/2000/svg" width="\d+" height="\d+" viewBox="0 0 \d+ \d+">.*</svg>~s', file_get_contents($iconFilePath), sprintf('The SVG metadata of the %s icon is different than expected (use the same as the other icons).', $iconFilePath));
}
public function provideIconFilePaths()

View File

@ -196,6 +196,10 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
$now = microtime(true);
if (0 === $expiry) {
$expiry = PHP_INT_MAX;
}
if (null !== $expiry && $expiry <= $now) {
$this->deleteItem($key);

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\PruneableInterface;
@ -162,6 +163,25 @@ class TagAwareAdapterTest extends AdapterTestCase
$this->assertFalse($anotherPool->hasItem($itemKey));
}
public function testInvalidateTagsWithArrayAdapter()
{
$adapter = new TagAwareAdapter(new ArrayAdapter());
$item = $adapter->getItem('foo');
$this->assertFalse($item->isHit());
$item->tag('bar');
$item->expiresAfter(100);
$adapter->save($item);
$this->assertTrue($adapter->getItem('foo')->isHit());
$adapter->invalidateTags(['bar']);
$this->assertFalse($adapter->getItem('foo')->isHit());
}
public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags()
{
$pool = $this->createCachePool();

View File

@ -81,7 +81,7 @@ class XmlUtilsTest extends TestCase
XmlUtils::loadFile($fixtures.'valid.xml', [$mock, 'validate']);
$this->fail();
} catch (\InvalidArgumentException $e) {
$this->assertRegExp('/The XML file ".+" is not valid\./', $e->getMessage());
$this->assertMatchesRegularExpression('/The XML file ".+" is not valid\./', $e->getMessage());
}
$this->assertInstanceOf('DOMDocument', XmlUtils::loadFile($fixtures.'valid.xml', [$mock, 'validate']));
@ -199,7 +199,9 @@ class XmlUtilsTest extends TestCase
// test for issue https://github.com/symfony/symfony/issues/9731
public function testLoadWrongEmptyXMLWithErrorHandler()
{
$originalDisableEntities = libxml_disable_entity_loader(false);
if (LIBXML_VERSION < 20900) {
$originalDisableEntities = libxml_disable_entity_loader(false);
}
$errorReporting = error_reporting(-1);
set_error_handler(function ($errno, $errstr) {
@ -219,12 +221,13 @@ class XmlUtilsTest extends TestCase
error_reporting($errorReporting);
}
$disableEntities = libxml_disable_entity_loader(true);
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(true);
libxml_disable_entity_loader($disableEntities);
libxml_disable_entity_loader($originalDisableEntities);
$this->assertFalse($disableEntities);
libxml_disable_entity_loader($originalDisableEntities);
$this->assertFalse($disableEntities);
}
// should not throw an exception
XmlUtils::loadFile(__DIR__.'/../Fixtures/Util/valid.xml', __DIR__.'/../Fixtures/Util/schema.xsd');

View File

@ -51,13 +51,17 @@ class XmlUtils
}
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);
if (LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(true);
}
libxml_clear_errors();
$dom = new \DOMDocument();
$dom->validateOnParse = true;
if (!$dom->loadXML($content, LIBXML_NONET | (\defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}
throw new XmlParsingException(implode("\n", static::getXmlErrors($internalErrors)));
}
@ -65,7 +69,9 @@ class XmlUtils
$dom->normalizeDocument();
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}
foreach ($dom->childNodes as $child) {
if (XML_DOCUMENT_TYPE_NODE === $child->nodeType) {

View File

@ -212,7 +212,7 @@ class TextDescriptor extends Descriptor
// calculate max. width based on available commands per namespace
$width = $this->getColumnWidth(array_merge(...array_values(array_map(function ($namespace) use ($commands) {
return array_intersect($namespace['commands'], array_keys($commands));
}, $namespaces))));
}, array_values($namespaces)))));
if ($describedNamespace) {
$this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);

View File

@ -559,9 +559,9 @@ class ApplicationTest extends TestCase
$this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
$this->assertRegExp('/foo1:bar/', $e->getMessage());
$this->assertRegExp('/foo:bar/', $e->getMessage());
$this->assertMatchesRegularExpression('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
$this->assertMatchesRegularExpression('/foo1:bar/', $e->getMessage());
$this->assertMatchesRegularExpression('/foo:bar/', $e->getMessage());
}
// Namespace + plural
@ -570,8 +570,8 @@ class ApplicationTest extends TestCase
$this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
$this->assertRegExp('/foo1/', $e->getMessage());
$this->assertMatchesRegularExpression('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
$this->assertMatchesRegularExpression('/foo1/', $e->getMessage());
}
$application->add(new \Foo3Command());
@ -583,8 +583,8 @@ class ApplicationTest extends TestCase
$this->fail('->find() should throw an Symfony\Component\Console\Exception\CommandNotFoundException if a command is ambiguous because of a subnamespace, with alternatives');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e);
$this->assertRegExp('/foo3:bar/', $e->getMessage());
$this->assertRegExp('/foo3:bar:toh/', $e->getMessage());
$this->assertMatchesRegularExpression('/foo3:bar/', $e->getMessage());
$this->assertMatchesRegularExpression('/foo3:bar:toh/', $e->getMessage());
}
}
@ -613,10 +613,10 @@ class ApplicationTest extends TestCase
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist');
$this->assertSame(['afoobar1', 'foo:bar1'], $e->getAlternatives());
$this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
$this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"');
$this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"');
$this->assertNotRegExp('/foo:bar(?!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');
$this->assertMatchesRegularExpression(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
$this->assertMatchesRegularExpression('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"');
$this->assertMatchesRegularExpression('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"');
$this->assertDoesNotMatchRegularExpression('/foo:bar(?!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');
}
}
@ -664,10 +664,10 @@ class ApplicationTest extends TestCase
$this->assertContains('foo', $e->getAlternatives());
$this->assertContains('foo1', $e->getAlternatives());
$this->assertContains('foo3', $e->getAlternatives());
$this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative');
$this->assertRegExp('/foo/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo"');
$this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo1"');
$this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo3"');
$this->assertMatchesRegularExpression('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative');
$this->assertMatchesRegularExpression('/foo/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo"');
$this->assertMatchesRegularExpression('/foo1/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo1"');
$this->assertMatchesRegularExpression('/foo3/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo3"');
}
}
@ -698,7 +698,7 @@ class ApplicationTest extends TestCase
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command is not defined');
$this->assertSame($expectedAlternatives, $e->getAlternatives());
$this->assertRegExp('/Command "foo" is not defined\..*Did you mean one of these\?.*/Ums', $e->getMessage());
$this->assertMatchesRegularExpression('/Command "foo" is not defined\..*Did you mean one of these\?.*/Ums', $e->getMessage());
}
}
@ -799,9 +799,9 @@ class ApplicationTest extends TestCase
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');
$tester->run(['command' => 'foo3:bar'], ['decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE]);
$this->assertRegExp('/\[Exception\]\s*First exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is default and verbosity is verbose');
$this->assertRegExp('/\[Exception\]\s*Second exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is 0 and verbosity is verbose');
$this->assertRegExp('/\[Exception \(404\)\]\s*Third exception/', $tester->getDisplay(), '->renderException() renders a pretty exception with code exception when code exception is 404 and verbosity is verbose');
$this->assertMatchesRegularExpression('/\[Exception\]\s*First exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is default and verbosity is verbose');
$this->assertMatchesRegularExpression('/\[Exception\]\s*Second exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is 0 and verbosity is verbose');
$this->assertMatchesRegularExpression('/\[Exception \(404\)\]\s*Third exception/', $tester->getDisplay(), '->renderException() renders a pretty exception with code exception when code exception is 404 and verbosity is verbose');
$tester->run(['command' => 'foo3:bar'], ['decorated' => true]);
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');
@ -1448,8 +1448,8 @@ class ApplicationTest extends TestCase
$application->setCatchExceptions(false);
$application->setDispatcher(new EventDispatcher());
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
new \UnknownClass();
$application->register('dym')->setCode(function () {
throw new \Error('Something went wrong.');
});
$tester = new ApplicationTester($application);
@ -1458,7 +1458,7 @@ class ApplicationTest extends TestCase
$tester->run(['command' => 'dym']);
$this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');
} catch (\Error $e) {
$this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');
$this->assertSame('Something went wrong.', $e->getMessage());
}
}
@ -1753,8 +1753,8 @@ class ApplicationTest extends TestCase
$application->setAutoExit(false);
$application->setDispatcher(new EventDispatcher());
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
new \UnknownClass();
$application->register('dym')->setCode(function () {
throw new \Error('Something went wrong.');
});
$tester = new ApplicationTester($application);
@ -1763,7 +1763,7 @@ class ApplicationTest extends TestCase
$tester->run(['command' => 'dym']);
$this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');
} catch (\Error $e) {
$this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');
$this->assertSame('Something went wrong.', $e->getMessage());
}
}

View File

@ -23,7 +23,7 @@ class ListCommandTest extends TestCase
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(['command' => $command->getName()], ['decorated' => false]);
$this->assertRegExp('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
$this->assertMatchesRegularExpression('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
}
public function testExecuteListsCommandsWithXmlOption()
@ -31,7 +31,7 @@ class ListCommandTest extends TestCase
$application = new Application();
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(['command' => $command->getName(), '--format' => 'xml']);
$this->assertRegExp('/<command id="list" name="list" hidden="0">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
$this->assertMatchesRegularExpression('/<command id="list" name="list" hidden="0">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
}
public function testExecuteListsCommandsWithRawOption()

View File

@ -624,9 +624,13 @@ $imports
EOF
;
$disableEntities = libxml_disable_entity_loader(false);
$valid = @$dom->schemaValidateSource($source);
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(false);
$valid = @$dom->schemaValidateSource($source);
libxml_disable_entity_loader($disableEntities);
} else {
$valid = @$dom->schemaValidateSource($source);
}
foreach ($tmpfiles as $tmpfile) {
@unlink($tmpfile);

View File

@ -207,7 +207,7 @@ class FileLoaderTest extends TestCase
$this->assertTrue($container->has(MissingParent::class));
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'{Class "?Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Fixtures\\\\Prototype\\\\BadClasses\\\\MissingClass"? not found}',
$container->getDefinition(MissingParent::class)->getErrors()[0]
);

View File

@ -77,7 +77,7 @@ class XmlFileLoaderTest extends TestCase
$this->fail('->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'parameters.ini'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
$this->assertMatchesRegularExpression(sprintf('#^Unable to parse file ".+%s": .+.$#', 'parameters.ini'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
$e = $e->getPrevious();
$this->assertInstanceOf('InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
@ -91,7 +91,7 @@ class XmlFileLoaderTest extends TestCase
$this->fail('->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD');
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'nonvalid.xml'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
$this->assertMatchesRegularExpression(sprintf('#^Unable to parse file ".+%s": .+.$#', 'nonvalid.xml'), $e->getMessage(), '->parseFileToDOM() throws an InvalidArgumentException if the loaded file is not a valid XML file');
$e = $e->getPrevious();
$this->assertInstanceOf('InvalidArgumentException', $e, '->parseFileToDOM() throws an InvalidArgumentException if the loaded file does not validate the XSD');
@ -104,13 +104,17 @@ class XmlFileLoaderTest extends TestCase
public function testLoadWithExternalEntitiesDisabled()
{
$disableEntities = libxml_disable_entity_loader(true);
if (LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(true);
}
$containerBuilder = new ContainerBuilder();
$loader = new XmlFileLoader($containerBuilder, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('services2.xml');
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}
$this->assertGreaterThan(0, $containerBuilder->getParameterBag()->all(), 'Parameters can be read from the config file.');
}
@ -532,7 +536,7 @@ class XmlFileLoaderTest extends TestCase
$this->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'services3.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
$this->assertMatchesRegularExpression(sprintf('#^Unable to parse file ".+%s": .+.$#', 'services3.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
$e = $e->getPrevious();
$this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
@ -569,7 +573,7 @@ class XmlFileLoaderTest extends TestCase
$this->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'services7.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
$this->assertMatchesRegularExpression(sprintf('#^Unable to parse file ".+%s": .+.$#', 'services7.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
$e = $e->getPrevious();
$this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
@ -620,7 +624,7 @@ class XmlFileLoaderTest extends TestCase
$this->fail('->load() throws an InvalidArgumentException if the configuration contains a document type');
} catch (\Exception $e) {
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration contains a document type');
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'withdoctype.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration contains a document type');
$this->assertMatchesRegularExpression(sprintf('#^Unable to parse file ".+%s": .+.$#', 'withdoctype.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration contains a document type');
$e = $e->getPrevious();
$this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration contains a document type');

View File

@ -654,7 +654,7 @@ class YamlFileLoaderTest extends TestCase
$this->assertCount(1, $args);
$this->assertInstanceOf(Reference::class, $args[0]);
$this->assertTrue($container->has((string) $args[0]));
$this->assertRegExp('/^\.\d+_Bar~[._A-Za-z0-9]{7}$/', (string) $args[0]);
$this->assertMatchesRegularExpression('/^\.\d+_Bar~[._A-Za-z0-9]{7}$/', (string) $args[0]);
$anonymous = $container->getDefinition((string) $args[0]);
$this->assertEquals('Bar', $anonymous->getClass());
@ -666,7 +666,7 @@ class YamlFileLoaderTest extends TestCase
$this->assertIsArray($factory);
$this->assertInstanceOf(Reference::class, $factory[0]);
$this->assertTrue($container->has((string) $factory[0]));
$this->assertRegExp('/^\.\d+_Quz~[._A-Za-z0-9]{7}$/', (string) $factory[0]);
$this->assertMatchesRegularExpression('/^\.\d+_Quz~[._A-Za-z0-9]{7}$/', (string) $factory[0]);
$this->assertEquals('constructFoo', $factory[1]);
$anonymous = $container->getDefinition((string) $factory[0]);

View File

@ -223,7 +223,9 @@ class Crawler implements \Countable, \IteratorAggregate
}
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);
if (LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(true);
}
$dom = new \DOMDocument('1.0', $charset);
$dom->validateOnParse = true;
@ -233,7 +235,9 @@ class Crawler implements \Countable, \IteratorAggregate
}
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}
$this->addDocument($dom);
@ -1119,7 +1123,9 @@ class Crawler implements \Countable, \IteratorAggregate
$htmlContent = $this->convertToHtmlEntities($htmlContent, $charset);
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);
if (LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(true);
}
$dom = new \DOMDocument('1.0', $charset);
$dom->validateOnParse = true;
@ -1129,7 +1135,9 @@ class Crawler implements \Countable, \IteratorAggregate
}
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}
return $dom;
}

View File

@ -282,7 +282,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->remove($basePath);
$this->assertFileNotExists($basePath);
$this->assertFileDoesNotExist($basePath);
}
public function testRemoveCleansArrayOfFilesAndDirectories()
@ -298,8 +298,8 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->remove($files);
$this->assertFileNotExists($basePath.'dir');
$this->assertFileNotExists($basePath.'file');
$this->assertFileDoesNotExist($basePath.'dir');
$this->assertFileDoesNotExist($basePath.'file');
}
public function testRemoveCleansTraversableObjectOfFilesAndDirectories()
@ -315,8 +315,8 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->remove($files);
$this->assertFileNotExists($basePath.'dir');
$this->assertFileNotExists($basePath.'file');
$this->assertFileDoesNotExist($basePath.'dir');
$this->assertFileDoesNotExist($basePath.'file');
}
public function testRemoveIgnoresNonExistingFiles()
@ -331,7 +331,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->remove($files);
$this->assertFileNotExists($basePath.'dir');
$this->assertFileDoesNotExist($basePath.'dir');
}
public function testRemoveCleansInvalidLinks()
@ -355,7 +355,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->remove($basePath);
$this->assertFileNotExists($basePath);
$this->assertFileDoesNotExist($basePath);
}
public function testFilesExists()
@ -793,7 +793,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->rename($file, $newPath);
$this->assertFileNotExists($file);
$this->assertFileDoesNotExist($file);
$this->assertFileExists($newPath);
}
@ -819,7 +819,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->rename($file, $newPath, true);
$this->assertFileNotExists($file);
$this->assertFileDoesNotExist($file);
$this->assertFileExists($newPath);
}
@ -1345,7 +1345,7 @@ class FilesystemTest extends FilesystemTestCase
$this->assertDirectoryExists($targetPath);
$this->assertFileExists($targetPath.'source');
$this->assertFileNotExists($targetPath.'target');
$this->assertFileDoesNotExist($targetPath.'target');
}
public function testMirrorAvoidCopyingTargetDirectoryIfInSourceDirectory()
@ -1469,7 +1469,7 @@ class FilesystemTest extends FilesystemTestCase
$this->assertStringStartsWith($scheme, $filename);
// The php://temp stream deletes the file after close
$this->assertFileNotExists($filename);
$this->assertFileDoesNotExist($filename);
}
public function testTempnamWithPharSchemeFails()

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Tests\Resources;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Xml\Loader;
class TranslationFilesTest extends TestCase
{
@ -20,7 +21,11 @@ class TranslationFilesTest extends TestCase
*/
public function testTranslationFileIsValid($filePath)
{
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
$loader = class_exists(Loader::class)
? [new Loader(), 'loadFile']
: ['PHPUnit\Util\XML', 'loadfile'];
$loader($filePath, false, false, true);
$this->addToAssertionCount(1);
}

View File

@ -309,7 +309,7 @@ class BinaryFileResponseTest extends ResponseTestCase
$response->prepare($request);
$response->sendContent();
$this->assertFileNotExists($path);
$this->assertFileDoesNotExist($path);
}
public function testAcceptRangeOnUnsafeMethods()

View File

@ -60,7 +60,7 @@ class FileTest extends TestCase
$this->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $movedFile);
$this->assertFileExists($targetPath);
$this->assertFileNotExists($path);
$this->assertFileDoesNotExist($path);
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
@unlink($targetPath);
@ -79,7 +79,7 @@ class FileTest extends TestCase
$movedFile = $file->move($targetDir, 'test.newname.gif');
$this->assertFileExists($targetPath);
$this->assertFileNotExists($path);
$this->assertFileDoesNotExist($path);
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
@unlink($targetPath);
@ -114,7 +114,7 @@ class FileTest extends TestCase
$this->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $movedFile);
$this->assertFileExists($targetPath);
$this->assertFileNotExists($path);
$this->assertFileDoesNotExist($path);
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
@unlink($targetPath);
@ -134,7 +134,7 @@ class FileTest extends TestCase
$movedFile = $file->move($targetDir);
$this->assertFileExists($targetPath);
$this->assertFileNotExists($sourcePath);
$this->assertFileDoesNotExist($sourcePath);
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
@unlink($sourcePath);

View File

@ -223,7 +223,7 @@ class UploadedFileTest extends TestCase
$movedFile = $file->move(__DIR__.'/Fixtures/directory');
$this->assertFileExists($targetPath);
$this->assertFileNotExists($path);
$this->assertFileDoesNotExist($path);
$this->assertEquals(realpath($targetPath), $movedFile->getRealPath());
@unlink($targetPath);

View File

@ -20,7 +20,7 @@ class RedirectResponseTest extends TestCase
{
$response = new RedirectResponse('foo.bar');
$this->assertRegExp('#<meta http-equiv="refresh" content="\d+;url=\'foo\.bar\'" />#', preg_replace('/\s+/', ' ', $response->getContent()));
$this->assertMatchesRegularExpression('#<meta http-equiv="refresh" content="\d+;url=\'foo\.bar\'" />#', preg_replace('/\s+/', ' ', $response->getContent()));
}
public function testRedirectResponseConstructorEmptyUrl()

View File

@ -309,6 +309,6 @@ class ResponseHeaderBagTest extends TestCase
private function assertSetCookieHeader(string $expected, ResponseHeaderBag $actual)
{
$this->assertRegExp('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
$this->assertMatchesRegularExpression('#^Set-Cookie:\s+'.preg_quote($expected, '#').'$#m', str_replace("\r\n", "\n", (string) $actual));
}
}

View File

@ -30,8 +30,8 @@ class ConfigDataCollectorTest extends TestCase
$this->assertSame('test', $c->getEnv());
$this->assertTrue($c->isDebug());
$this->assertSame('config', $c->getName());
$this->assertRegExp('~^'.preg_quote($c->getPhpVersion(), '~').'~', PHP_VERSION);
$this->assertRegExp('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', PHP_VERSION);
$this->assertMatchesRegularExpression('~^'.preg_quote($c->getPhpVersion(), '~').'~', PHP_VERSION);
$this->assertMatchesRegularExpression('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', PHP_VERSION);
$this->assertSame(PHP_INT_SIZE * 8, $c->getPhpArchitecture());
$this->assertSame(class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale());
$this->assertSame(date_default_timezone_get(), $c->getPhpTimezone());

View File

@ -51,7 +51,7 @@ class RequestDataCollectorTest extends TestCase
$this->assertEquals(['name' => 'foo'], $c->getRouteParams());
$this->assertSame([], $c->getSessionAttributes());
$this->assertSame('en', $c->getLocale());
$this->assertContains(__FILE__, $attributes->get('resource'));
$this->assertContainsEquals(__FILE__, $attributes->get('resource'));
$this->assertSame('stdClass', $attributes->get('object')->getType());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders());

View File

@ -654,7 +654,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTraceContains('miss');
$this->assertTraceContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=10/', $this->response->headers->get('Cache-Control'));
$this->assertMatchesRegularExpression('/s-maxage=10/', $this->response->headers->get('Cache-Control'));
$this->cacheConfig['default_ttl'] = 10;
$this->request('GET', '/');
@ -663,7 +663,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTraceContains('fresh');
$this->assertTraceNotContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=10/', $this->response->headers->get('Cache-Control'));
$this->assertMatchesRegularExpression('/s-maxage=10/', $this->response->headers->get('Cache-Control'));
}
public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpired()
@ -676,7 +676,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTraceContains('miss');
$this->assertTraceContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->assertMatchesRegularExpression('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->request('GET', '/');
$this->assertHttpKernelIsNotCalled();
@ -684,7 +684,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTraceContains('fresh');
$this->assertTraceNotContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->assertMatchesRegularExpression('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
// expires the cache
$values = $this->getMetaStorageValues();
@ -704,7 +704,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTraceContains('invalid');
$this->assertTraceContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->assertMatchesRegularExpression('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->setNextResponse();
@ -714,7 +714,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTraceContains('fresh');
$this->assertTraceNotContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->assertMatchesRegularExpression('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
}
public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpiredWithStatus304()
@ -727,7 +727,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTraceContains('miss');
$this->assertTraceContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->assertMatchesRegularExpression('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->request('GET', '/');
$this->assertHttpKernelIsNotCalled();
@ -755,7 +755,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTraceContains('store');
$this->assertTraceNotContains('miss');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->assertMatchesRegularExpression('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->request('GET', '/');
$this->assertHttpKernelIsNotCalled();
@ -763,7 +763,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertTraceContains('fresh');
$this->assertTraceNotContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
$this->assertMatchesRegularExpression('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
}
public function testDoesNotAssignDefaultTtlWhenResponseHasMustRevalidateDirective()
@ -776,7 +776,7 @@ class HttpCacheTest extends HttpCacheTestCase
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertTraceContains('miss');
$this->assertTraceNotContains('store');
$this->assertNotRegExp('/s-maxage/', $this->response->headers->get('Cache-Control'));
$this->assertDoesNotMatchRegularExpression('/s-maxage/', $this->response->headers->get('Cache-Control'));
$this->assertEquals('Hello World', $this->response->getContent());
}

View File

@ -91,7 +91,7 @@ class HttpCacheTestCase extends TestCase
$traces = $this->cache->getTraces();
$traces = current($traces);
$this->assertRegExp('/'.$trace.'/', implode(', ', $traces));
$this->assertMatchesRegularExpression('/'.$trace.'/', implode(', ', $traces));
}
public function assertTraceNotContains($trace)
@ -99,7 +99,7 @@ class HttpCacheTestCase extends TestCase
$traces = $this->cache->getTraces();
$traces = current($traces);
$this->assertNotRegExp('/'.$trace.'/', implode(', ', $traces));
$this->assertDoesNotMatchRegularExpression('/'.$trace.'/', implode(', ', $traces));
}
public function assertExceptionsAreCaught()

View File

@ -87,7 +87,7 @@ class KernelTest extends TestCase
$containerDir = __DIR__.'/Fixtures/var/cache/custom/'.substr(\get_class($kernel->getContainer()), 0, 16);
$this->assertTrue(unlink(__DIR__.'/Fixtures/var/cache/custom/Symfony_Component_HttpKernel_Tests_CustomProjectDirKernelCustomDebugContainer.php.meta'));
$this->assertFileExists($containerDir);
$this->assertFileNotExists($containerDir.'.legacy');
$this->assertFileDoesNotExist($containerDir.'.legacy');
$kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); });
$kernel->boot();
@ -95,8 +95,8 @@ class KernelTest extends TestCase
$this->assertFileExists($containerDir);
$this->assertFileExists($containerDir.'.legacy');
$this->assertFileNotExists($legacyContainerDir);
$this->assertFileNotExists($legacyContainerDir.'.legacy');
$this->assertFileDoesNotExist($legacyContainerDir);
$this->assertFileDoesNotExist($legacyContainerDir.'.legacy');
}
public function testBootInitializesBundlesAndContainer()

View File

@ -318,8 +318,8 @@ class FileProfilerStorageTest extends TestCase
$tokens = $this->storage->find('', '', 10, '');
$this->assertCount(2, $tokens);
$this->assertContains($tokens[0]['status_code'], [200, 404]);
$this->assertContains($tokens[1]['status_code'], [200, 404]);
$this->assertContains((int) $tokens[0]['status_code'], [200, 404]);
$this->assertContains((int) $tokens[1]['status_code'], [200, 404]);
}
public function testMultiRowIndexFile()

View File

@ -54,7 +54,7 @@ class GitRepositoryTest extends TestCase
$this->assertDirectoryExists($this->targetDir.'/.git');
$this->assertSame($this->targetDir, $git->getPath());
$this->assertSame(self::REPO_URL, $git->getUrl());
$this->assertRegExp('#^[0-9a-z]{40}$#', $git->getLastCommitHash());
$this->assertMatchesRegularExpression('#^[0-9a-z]{40}$#', $git->getLastCommitHash());
$this->assertNotEmpty($git->getLastAuthor());
$this->assertInstanceOf('DateTime', $git->getLastAuthoredDate());
$this->assertStringMatchesFormat('v%s', $git->getLastTag());

View File

@ -93,6 +93,11 @@ class AnnotationFileLoader extends FileLoader
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain PHP code. Did you forgot to add the "<?php" start tag at the beginning of the file?', $file));
}
$nsTokens = [T_NS_SEPARATOR => true, T_STRING => true];
if (\defined('T_NAME_QUALIFIED')) {
$nsTokens[T_NAME_QUALIFIED] = true;
}
for ($i = 0; isset($tokens[$i]); ++$i) {
$token = $tokens[$i];
@ -104,9 +109,9 @@ class AnnotationFileLoader extends FileLoader
return $namespace.'\\'.$token[1];
}
if (true === $namespace && T_STRING === $token[0]) {
if (true === $namespace && isset($nsTokens[$token[0]])) {
$namespace = $token[1];
while (isset($tokens[++$i][1]) && \in_array($tokens[$i][0], [T_NS_SEPARATOR, T_STRING])) {
while (isset($tokens[++$i][1], $nsTokens[$tokens[$i][0]])) {
$namespace .= $tokens[$i][1];
}
$token = $tokens[$i];

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Core\Tests\Resources;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Xml\Loader;
class TranslationFilesTest extends TestCase
{
@ -20,7 +21,11 @@ class TranslationFilesTest extends TestCase
*/
public function testTranslationFileIsValid($filePath)
{
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
$loader = class_exists(Loader::class)
? [new Loader(), 'loadFile']
: ['PHPUnit\Util\XML', 'loadfile'];
$loader($filePath, false, false, true);
$this->addToAssertionCount(1);
}

View File

@ -115,14 +115,18 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
}
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);
if (LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(true);
}
libxml_clear_errors();
$dom = new \DOMDocument();
$dom->loadXML($data, $context[self::LOAD_OPTIONS] ?? $this->defaultContext[self::LOAD_OPTIONS]);
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}
if ($error = libxml_get_last_error()) {
libxml_clear_errors();
@ -473,6 +477,9 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
$node->appendChild($child);
} elseif ($val instanceof \Traversable) {
$this->buildXml($node, $val);
} elseif ($val instanceof \DOMNode) {
$child = $this->dom->importNode($val, true);
$node->appendChild($child);
} elseif (\is_object($val)) {
if (null === $this->serializer) {
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
@ -487,9 +494,6 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
return $this->appendText($node, $val);
} elseif (\is_bool($val)) {
return $this->appendText($node, (int) $val);
} elseif ($val instanceof \DOMNode) {
$child = $this->dom->importNode($val, true);
$node->appendChild($child);
}
return true;

View File

@ -756,6 +756,20 @@ XML;
$this->assertEquals($expectedXml, $actualXml);
}
public function testEncodeXmlWithDomNodeValue()
{
$expectedXml = <<<'XML'
<?xml version="1.0"?>
<response><foo>bar</foo><bar>foo &amp; bar</bar></response>
XML;
$document = new \DOMDocument();
$actualXml = $this->encoder->encode(['foo' => $document->createTextNode('bar'), 'bar' => $document->createTextNode('foo & bar')], 'xml');
$this->assertEquals($expectedXml, $actualXml);
}
public function testEncodeXmlWithDateTimeObjectValue()
{
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();

View File

@ -49,13 +49,17 @@ class XliffFileLoaderTest extends TestCase
public function testLoadWithExternalEntitiesDisabled()
{
$disableEntities = libxml_disable_entity_loader(true);
if (LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(true);
}
$loader = new XliffFileLoader();
$resource = __DIR__.'/../fixtures/resources.xlf';
$catalogue = $loader->load($resource, 'en', 'domain1');
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}
$this->assertEquals('en', $catalogue->getLocale());
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());

View File

@ -348,12 +348,12 @@ class TranslatorTest extends TestCase
$resources = $translator->getCatalogue('en')->getResources();
$this->assertCount(1, $resources);
$this->assertContains(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'resources.yml', $resources);
$this->assertContainsEquals(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'resources.yml', $resources);
$resources = $translator->getCatalogue('en_GB')->getResources();
$this->assertCount(2, $resources);
$this->assertContains(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'empty.yml', $resources);
$this->assertContains(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'resources.yml', $resources);
$this->assertContainsEquals(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'empty.yml', $resources);
$this->assertContainsEquals(__DIR__.\DIRECTORY_SEPARATOR.'fixtures'.\DIRECTORY_SEPARATOR.'resources.yml', $resources);
}
/**

View File

@ -61,16 +61,22 @@ class XliffUtils
{
$xliffVersion = static::getVersionNumber($dom);
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(false);
if (LIBXML_VERSION < 20900) {
$disableEntities = libxml_disable_entity_loader(false);
}
$isValid = @$dom->schemaValidateSource(self::getSchema($xliffVersion));
if (!$isValid) {
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}
return self::getXmlErrors($internalErrors);
}
libxml_disable_entity_loader($disableEntities);
if (LIBXML_VERSION < 20900) {
libxml_disable_entity_loader($disableEntities);
}
$dom->normalizeDocument();

View File

@ -382,6 +382,10 @@
<source>Each element of this collection should satisfy its own set of constraints.</source>
<target>Jedes Element dieser Sammlung sollte seine eigene Menge an Bedingungen erfüllen.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
<target>Dieser Wert ist keine gültige Internationale Wertpapierkennnummer (ISIN).</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -382,6 +382,10 @@
<source>Each element of this collection should satisfy its own set of constraints.</source>
<target>Each element of this collection should satisfy its own set of constraints.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
<target>This value is not a valid International Securities Identification Number (ISIN).</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -382,6 +382,10 @@
<source>Each element of this collection should satisfy its own set of constraints.</source>
<target>Chaque élément de cette collection doit satisfaire à son propre jeu de contraintes.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
<target>Cette valeur n'est pas un code international de sécurité valide (ISIN).</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -362,6 +362,22 @@
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
<target>Naikalat ang password na ito sa isang data breach at hindi na dapat gamitin. Mangyaring gumamit ng ibang pang password.</target>
</trans-unit>
<trans-unit id="94">
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>Ang halagang ito ay dapat nasa pagitan ng {{ min }} at {{ max }}.</target>
</trans-unit>
<trans-unit id="95">
<source>This value is not a valid hostname.</source>
<target>Ang halagang ito ay hindi wastong hostname.</target>
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<target>Ang bilang ng mga elemento sa koleksyon na ito ay dapat multiple ng {{ compared_value }}.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
<target>Ang halagang ito ay hindi wastong International Securities Identification Number (ISIN).</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -382,6 +382,10 @@
<source>Each element of this collection should satisfy its own set of constraints.</source>
<target>Mỗi phần tử trong bộ sưu tập này nên thỏa mãn những ràng buộc của nó.</target>
</trans-unit>
<trans-unit id="99">
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
<target>Giá trị này không phải là mã số chứng khoán quốc tế (ISIN) hợp lệ.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Validator\Tests\Resources;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Xml\Loader;
class TranslationFilesTest extends TestCase
{
@ -20,7 +21,11 @@ class TranslationFilesTest extends TestCase
*/
public function testTranslationFileIsValid($filePath)
{
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
$loader = class_exists(Loader::class)
? [new Loader(), 'loadFile']
: ['PHPUnit\Util\XML', 'loadfile'];
$loader($filePath, false, false, true);
$this->addToAssertionCount(1);
}

View File

@ -269,6 +269,10 @@ class CliDumper extends AbstractDumper
*/
public function enterHash(Cursor $cursor, int $type, $class, bool $hasChild)
{
if (null === $this->colors) {
$this->colors = $this->supportsColors();
}
$this->dumpKey($cursor);
$attr = $cursor->attr;
@ -283,8 +287,7 @@ class CliDumper extends AbstractDumper
} elseif (Cursor::HASH_RESOURCE === $type) {
$prefix = $this->style('note', $class.' resource', $attr).($hasChild ? ' {' : ' ');
} else {
$unstyledPrefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? 'array:'.$class : '';
$prefix = $this->style('note', $unstyledPrefix, $attr).($unstyledPrefix ? ' [' : '[');
$prefix = $class && !(self::DUMP_LIGHT_ARRAY & $this->flags) ? $this->style('note', 'array:'.$class).' [' : '[';
}
if (($cursor->softRefCount || 0 < $cursor->softRefHandle) && empty($attr['cut_hash'])) {

View File

@ -495,7 +495,7 @@ EOTXT
yield [
['foo' => 'bar'],
0,
<<<EOTXT
<<<EOTXT
\e[0;38;5;208m\e[38;5;38marray:1\e[0;38;5;208m [\e[m
\e[0;38;5;208m"\e[38;5;113mfoo\e[0;38;5;208m" => "\e[1;38;5;113mbar\e[0;38;5;208m"\e[m
\e[0;38;5;208m]\e[m
@ -503,20 +503,20 @@ EOTXT
EOTXT
];
yield [[], AbstractDumper::DUMP_LIGHT_ARRAY, "\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[]\e[m\n"];
yield [[], AbstractDumper::DUMP_LIGHT_ARRAY, "\e[0;38;5;208m[]\e[m\n"];
yield [
['foo' => 'bar'],
AbstractDumper::DUMP_LIGHT_ARRAY,
<<<EOTXT
\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[\e[m
\e[0;38;5;208m[\e[m
\e[0;38;5;208m"\e[38;5;113mfoo\e[0;38;5;208m" => "\e[1;38;5;113mbar\e[0;38;5;208m"\e[m
\e[0;38;5;208m]\e[m
EOTXT
];
yield [[], 0, "\e[0;38;5;208m\e[38;5;38m\e[0;38;5;208m[]\e[m\n"];
yield [[], 0, "\e[0;38;5;208m[]\e[m\n"];
}
/**

View File

@ -34,7 +34,7 @@ class LintCommandTest extends TestCase
$ret = $tester->execute(['filename' => $filename], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertRegExp('/^\/\/ OK in /', trim($tester->getDisplay()));
$this->assertMatchesRegularExpression('/^\/\/ OK in /', trim($tester->getDisplay()));
}
public function testLintCorrectFiles()