diff --git a/core/modules/simpletest/src/Tests/SkipDeprecationsTest.php b/core/modules/simpletest/src/Tests/SkipDeprecationsTest.php new file mode 100644 index 0000000000..b5ae8f886c --- /dev/null +++ b/core/modules/simpletest/src/Tests/SkipDeprecationsTest.php @@ -0,0 +1,36 @@ +drupalGet(Url::fromRoute('deprecation_test.route')); + } + +} diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 22cd768187..14ce832ae5 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -206,6 +206,23 @@ */ protected $customTranslations; + /** + * User deprecations to skip. + * + * If the test is using code that causes a warning via a silently triggered + * E_USER_DEPRECATED error then this can be used to skip this error for a + * particular test. Note, that this is means there is technical debt that + * needs to be addressed. This should not be used for testing expected + * deprecations. To test for expected deprecations change the test to a + * PHPUnit based test and use the @expectedDeprecation annotation and add + * @group legacy. + * + * @see \Drupal\Tests\Listeners\DeprecationListener::getSkippedDeprecations() + * + * @var array + */ + public static $skippedDeprecations = []; + /** * Constructor for \Drupal\simpletest\WebTestBase. */ @@ -696,7 +713,7 @@ protected function curlHeaderCallback($curlHandler, $header) { if ($parameters[1] === 'User deprecated function') { if (getenv('SYMFONY_DEPRECATIONS_HELPER') !== 'disabled') { $message = (string) $parameters[0]; - if (!in_array($message, DeprecationListener::getSkippedDeprecations())) { + if (!in_array($message, DeprecationListener::getSkippedDeprecations(get_class($this)))) { call_user_func_array([&$this, 'error'], $parameters); } } diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index 3e54b3f085..c489c44a02 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -221,6 +221,22 @@ 'config_test.dynamic.system', ]; + /** + * User deprecations to skip. + * + * If the test is using code that causes a warning via a silently triggered + * E_USER_DEPRECATED error then this can be used to skip this error for a + * particular test. Note, that this is means there is technical debt that + * needs to be addressed. This should not be used for testing expected + * deprecations. To test for expected deprecations use the + * @expectedDeprecation annotation and add @group legacy. + * + * @see \Drupal\Tests\Listeners\DeprecationListener::getSkippedDeprecations() + * + * @var array + */ + public static $skippedDeprecations = []; + /** * {@inheritdoc} */ diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 6ac72f30c3..b53605603e 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -274,6 +274,22 @@ */ protected $originalContainer; + /** + * User deprecations to skip. + * + * If the test is using code that causes a warning via a silently triggered + * E_USER_DEPRECATED error then this can be used to skip this error for a + * particular test. Note, that this is means there is technical debt that + * needs to be addressed. This should not be used for testing expected + * deprecations. To test for expected deprecations use the + * @expectedDeprecation annotation and add @group legacy. + * + * @see \Drupal\Tests\Listeners\DeprecationListener::getSkippedDeprecations() + * + * @var array + */ + public static $skippedDeprecations = []; + /** * {@inheritdoc} */ diff --git a/core/tests/Drupal/Tests/Core/Test/SkippedDeprecationsTest.php b/core/tests/Drupal/Tests/Core/Test/SkippedDeprecationsTest.php new file mode 100644 index 0000000000..8667986ac8 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Test/SkippedDeprecationsTest.php @@ -0,0 +1,32 @@ +addToAssertionCount(1); + } + +} diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListener.php b/core/tests/Drupal/Tests/Listeners/DeprecationListener.php index 3673376d61..279e0145ad 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListener.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListener.php @@ -21,7 +21,7 @@ public function endTest(\PHPUnit_Framework_Test $test, $time) { $deprecations = $deprecations ? unserialize($deprecations) : []; $resave = FALSE; foreach ($deprecations as $key => $deprecation) { - if (in_array($deprecation[1], static::getSkippedDeprecations())) { + if (in_array($deprecation[1], static::getSkippedDeprecations(get_class($test)))) { unset($deprecations[$key]); $resave = TRUE; } @@ -35,13 +35,20 @@ public function endTest(\PHPUnit_Framework_Test $test, $time) { /** * A list of deprecations to ignore whilst fixes are put in place. * + * @param string $test_class + * The current test class being run. + * * @return string[] * A list of deprecations to ignore. * * @internal */ - public static function getSkippedDeprecations() { - return [ + public static function getSkippedDeprecations($test_class) { + $skipped_deprecations = []; + if (isset($test_class::$skippedDeprecations) && is_array($test_class::$skippedDeprecations)) { + $skipped_deprecations = $test_class::$skippedDeprecations; + } + return array_merge($skipped_deprecations, [ 'As of 3.1 an Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface is used to resolve arguments. In 4.0 the $argumentResolver becomes the Symfony\Component\HttpKernel\Controller\ArgumentResolver if no other is provided instead of using the $resolver argument.', 'Symfony\Component\HttpKernel\Controller\ControllerResolver::getArguments is deprecated as of 3.1 and will be removed in 4.0. Implement the Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface and inject it in the HttpKernel instead.', 'The Twig_Node::getLine method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', @@ -111,7 +118,7 @@ public static function getSkippedDeprecations() { 'The Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate_drupal\Plugin\migrate\source\d6\VariableTranslation', 'Implicit cacheability metadata bubbling (onto the global render context) in normalizers is deprecated since Drupal 8.5.0 and will be removed in Drupal 9.0.0. Use the "cacheability" serialization context instead, for explicit cacheability metadata bubbling. See https://www.drupal.org/node/2918937', 'Automatically creating the first item for computed fields is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\TypedData\ComputedItemListTrait instead.', - ]; + ]); } }