From 42e71505f5cfa5d35d5d12ec110d9e1ce931d50e Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu, 15 Mar 2018 00:06:13 +0000
Subject: [PATCH] Issue #2945247 by Mile23: Remove usages of @deprecated
 simpletest functions

---
 core/modules/simpletest/simpletest.module     |  4 ++-
 .../src/Kernel/SimpletestDeprecationTest.php  | 28 +++++++++++++++++++
 core/scripts/run-tests.sh                     | 10 ++++---
 3 files changed, 37 insertions(+), 5 deletions(-)
 create mode 100644 core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php

diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module
index 6670e5acc0be..dd05ddc1ca71 100644
--- a/core/modules/simpletest/simpletest.module
+++ b/core/modules/simpletest/simpletest.module
@@ -403,7 +403,7 @@ function simpletest_phpunit_command() {
  * Implements callback_batch_operation().
  */
 function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
-  simpletest_classloader_register();
+  \Drupal::service('test_discovery')->registerTestNamespaces();
   // Get working values.
   if (!isset($context['sandbox']['max'])) {
     // First iteration: initialize working values.
@@ -587,6 +587,7 @@ function simpletest_log_read($test_id, $database_prefix, $test_class) {
  *   instead.
  */
 function simpletest_test_get_all($extension = NULL, array $types = []) {
+  @trigger_error('The ' . __FUNCTION__ . ' function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service(\'test_discovery\')->getTestClasses($extension, $types) instead.', E_USER_DEPRECATED);
   return \Drupal::service('test_discovery')->getTestClasses($extension, $types);
 }
 
@@ -597,6 +598,7 @@ function simpletest_test_get_all($extension = NULL, array $types = []) {
  *   \Drupal::service('test_discovery')->registerTestNamespaces() instead.
  */
 function simpletest_classloader_register() {
+  @trigger_error('The ' . __FUNCTION__ . ' function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service(\'test_discovery\')->registerTestNamespaces() instead.', E_USER_DEPRECATED);
   \Drupal::service('test_discovery')->registerTestNamespaces();
 }
 
diff --git a/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php b/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php
new file mode 100644
index 000000000000..384f8c1b9b36
--- /dev/null
+++ b/core/modules/simpletest/tests/src/Kernel/SimpletestDeprecationTest.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace Drupal\Tests\simpletest\Kernel;
+
+use Drupal\KernelTests\KernelTestBase;
+
+/**
+ * Verify deprecation of simpletest.
+ *
+ * @group simpletest
+ * @group legacy
+ */
+class SimpletestDeprecationTest extends KernelTestBase {
+
+  public static $modules = ['simpletest'];
+
+  /**
+   * @expectedDeprecation The simpletest_phpunit_configuration_filepath function is deprecated since version 8.4.x and will be removed in 9.0.0.
+   * @expectedDeprecation The simpletest_test_get_all function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service('test_discovery')->getTestClasses($extension, $types) instead.
+   * @expectedDeprecation The simpletest_classloader_register function is deprecated in version 8.3.x and will be removed in 9.0.0. Use \Drupal::service('test_discovery')->registerTestNamespaces() instead.
+   */
+  public function testDeprecatedFunctions() {
+    $this->assertNotEmpty(simpletest_phpunit_configuration_filepath());
+    $this->assertNotEmpty(simpletest_test_get_all());
+    simpletest_classloader_register();
+  }
+
+}
diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index e1ef7db73711..eb77e135f325 100644
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -64,7 +64,7 @@
   echo "\nAvailable test groups & classes\n";
   echo "-------------------------------\n\n";
   try {
-    $groups = simpletest_test_get_all($args['module']);
+    $groups = \Drupal::service('test_discovery')->getTestClasses($args['module']);
   }
   catch (Exception $e) {
     error_log((string) $e);
@@ -1004,11 +1004,13 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
 function simpletest_script_get_test_list() {
   global $args;
 
+  /** $test_discovery \Drupal\simpletest\TestDiscovery */
+  $test_discovery = \Drupal::service('test_discovery');
   $types_processed = empty($args['types']);
   $test_list = [];
   if ($args['all'] || $args['module']) {
     try {
-      $groups = simpletest_test_get_all($args['module'], $args['types']);
+      $groups = $test_discovery->getTestClasses($args['module'], $args['types']);
       $types_processed = TRUE;
     }
     catch (Exception $e) {
@@ -1031,7 +1033,7 @@ function simpletest_script_get_test_list() {
         }
         else {
           try {
-            $groups = simpletest_test_get_all(NULL, $args['types']);
+            $groups = $test_discovery->getTestClasses(NULL, $args['types']);
           }
           catch (Exception $e) {
             echo (string) $e;
@@ -1132,7 +1134,7 @@ function simpletest_script_get_test_list() {
     }
     else {
       try {
-        $groups = simpletest_test_get_all(NULL, $args['types']);
+        $groups = $test_discovery->getTestClasses(NULL, $args['types']);
         $types_processed = TRUE;
       }
       catch (Exception $e) {
-- 
GitLab