View source
<?php
namespace Drupal\Tests\Listeners;
use PHPUnit\Util\Test;
trait DeprecationListenerTrait {
private $previousHandler;
protected function deprecationEndTest($test, $time) {
if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
$method = $test
->getName(FALSE);
if (strpos($method, 'testLegacy') === 0 || strpos($method, 'provideLegacy') === 0 || strpos($method, 'getLegacy') === 0 || strpos(get_class($test), '\\Legacy') || in_array('legacy', Test::getGroups(get_class($test), $method), TRUE)) {
return;
}
$deprecations = file_get_contents($file);
$deprecations = $deprecations ? unserialize($deprecations) : [];
$resave = FALSE;
foreach ($deprecations as $key => $deprecation) {
if (static::isDeprecationSkipped($deprecation[1])) {
unset($deprecations[$key]);
$resave = TRUE;
}
}
if ($resave) {
file_put_contents($file, serialize($deprecations));
}
}
}
public static function isDeprecationSkipped($message) {
if (in_array($message, static::getSkippedDeprecations(), TRUE)) {
return TRUE;
}
$dynamic_skipped_deprecations = [
'%The "[^"]+" class extends "Symfony\\\\Component\\\\EventDispatcher\\\\Event" that is deprecated since Symfony 4\\.3, use "Symfony\\\\Contracts\\\\EventDispatcher\\\\Event" instead\\.$%',
'%The "Symfony\\\\Component\\\\Validator\\\\Context\\\\ExecutionContextInterface::.*\\(\\)" method is considered internal Used by the validator engine. Should not be called by user\\s\\*\\s*code\\. It may change without further notice\\. You should not extend it from "[^"]+".%',
'%The "PHPUnit\\\\Framework\\\\TestCase::addWarning\\(\\)" method is considered internal%',
'%The entity link url update for the "\\w+" view is deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. Module-provided Views configuration should be updated to accommodate the changes described at https://www.drupal.org/node/2857891.%',
'%The operator defaults update for the "\\w+" view is deprecated in drupal:9.0.0 and is removed from drupal:10.0.0. Module-provided Views configuration should be updated to accommodate the changes described at https://www.drupal.org/node/2869168.%',
];
return (bool) preg_filter($dynamic_skipped_deprecations, '$0', $message);
}
public static function getSkippedDeprecations() {
return [
'\\Drupal\\Tests\\SkippedDeprecationTest deprecation',
'The "Symfony\\Component\\HttpFoundation\\File\\MimeType\\MimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\\Component\\Mime\\MimeTypes" instead.',
'The "Drupal\\Core\\File\\MimeType\\MimeTypeGuesser" class implements "Symfony\\Component\\HttpFoundation\\File\\MimeType\\MimeTypeGuesserInterface" that is deprecated since Symfony 4.3, use {@link MimeTypesInterface} instead.',
'The "Symfony\\Component\\HttpFoundation\\File\\MimeType\\FileBinaryMimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\\Component\\Mime\\FileBinaryMimeTypeGuesser" instead.',
'The "Symfony\\Component\\HttpFoundation\\File\\MimeType\\FileinfoMimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\\Component\\Mime\\FileinfoMimeTypeGuesser" instead.',
'The "Drupal\\Tests\\Core\\DependencyInjection\\Compiler\\LegacyMimeTypeGuesser" class implements "Symfony\\Component\\HttpFoundation\\File\\MimeType\\MimeTypeGuesserInterface" that is deprecated since Symfony 4.3, use {@link MimeTypesInterface} instead.',
'The "Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher::dispatch()" method will require a new "string|null $eventName" argument in the next major version of its interface "Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface", not defining it is deprecated.',
'The "Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher::dispatch()" method will require a new "string|null $eventName" argument in the next major version of its parent class "Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface", not defining it is deprecated.',
'The "Twig\\Environment::getTemplateClass()" method is considered internal. It may change without further notice. You should not extend it from "Drupal\\Core\\Template\\TwigEnvironment".',
'"Symfony\\Component\\DomCrawler\\Crawler::text()" will normalize whitespaces by default in Symfony 5.0, set the second "$normalizeWhitespace" argument to false to retrieve the non-normalized version of the text.',
"The \"PHPUnit\\TextUI\\ResultPrinter\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\\Tests\\Listeners\\HtmlOutputPrinter\".",
"The \"Drupal\\Tests\\Listeners\\DrupalListener\" class implements \"PHPUnit\\Framework\\TestListener\" that is deprecated Use the `TestHook` interfaces instead.",
"The \"Drupal\\Tests\\Listeners\\DrupalListener\" class uses \"PHPUnit\\Framework\\TestListenerDefaultImplementation\" that is deprecated The `TestListener` interface is deprecated.",
"The \"PHPUnit\\Framework\\TestSuite\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\\Tests\\TestSuites\\TestSuiteBase\".",
"The \"PHPUnit\\TextUI\\DefaultResultPrinter\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\\Tests\\Listeners\\HtmlOutputPrinter\".",
];
}
protected function registerErrorHandler() {
if ($this->previousHandler || 'disabled' === getenv('SYMFONY_DEPRECATIONS_HELPER')) {
return;
}
$deprecation_handler = function ($type, $msg, $file, $line, $context = []) {
if ($type === E_USER_DEPRECATED && static::isDeprecationSkipped($msg)) {
return;
}
return call_user_func($this->previousHandler, $type, $msg, $file, $line, $context);
};
$this->previousHandler = set_error_handler($deprecation_handler);
}
protected function removeErrorHandler() : void {
if ($this->previousHandler) {
$this->previousHandler = NULL;
restore_error_handler();
}
}
}