From 614ff9d255efea5cf9f34d27f991b1b8dba5ff7a Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Fri, 2 Feb 2024 11:26:12 +0000
Subject: [PATCH] Issue #3418379 by mondrake, Spokje: Deprecate
 Drupal\Tests\TestRequirementsTrait::checkRequirements and
 ::checkModuleRequirements

---
 .../tests/src/Functional/FileUploadTest.php   | 36 +++++++++----------
 .../Core/Test/BrowserTestBaseTest.php         |  3 ++
 .../Drupal/KernelTests/KernelTestBase.php     |  2 +-
 .../Drupal/KernelTests/KernelTestBaseTest.php |  8 +++++
 .../Drupal/Tests/TestRequirementsTrait.php    | 14 ++++++++
 ...rowserMissingDependentModuleMethodTest.php |  7 ++++
 .../BrowserMissingDependentModuleTest.php     |  7 ++++
 ...KernelMissingDependentModuleMethodTest.php |  7 ++++
 .../KernelMissingDependentModuleTest.php      |  7 ++++
 9 files changed, 72 insertions(+), 19 deletions(-)

diff --git a/core/modules/jsonapi/tests/src/Functional/FileUploadTest.php b/core/modules/jsonapi/tests/src/Functional/FileUploadTest.php
index 07f9dedd8073..a2044f12d1ac 100644
--- a/core/modules/jsonapi/tests/src/Functional/FileUploadTest.php
+++ b/core/modules/jsonapi/tests/src/Functional/FileUploadTest.php
@@ -147,45 +147,45 @@ protected function setUp(): void {
 
   /**
    * {@inheritdoc}
-   *
-   * @requires module irrelevant_for_this_test
    */
-  public function testGetIndividual() {}
+  public function testGetIndividual() {
+    $this->markTestSkipped('Irrelevant for this test');
+  }
 
   /**
    * {@inheritdoc}
-   *
-   * @requires module irrelevant_for_this_test
    */
-  public function testPostIndividual() {}
+  public function testPostIndividual() {
+    $this->markTestSkipped('Irrelevant for this test');
+  }
 
   /**
    * {@inheritdoc}
-   *
-   * @requires module irrelevant_for_this_test
    */
-  public function testPatchIndividual() {}
+  public function testPatchIndividual() {
+    $this->markTestSkipped('Irrelevant for this test');
+  }
 
   /**
    * {@inheritdoc}
-   *
-   * @requires module irrelevant_for_this_test
    */
-  public function testDeleteIndividual() {}
+  public function testDeleteIndividual() {
+    $this->markTestSkipped('Irrelevant for this test');
+  }
 
   /**
    * {@inheritdoc}
-   *
-   * @requires module irrelevant_for_this_test
    */
-  public function testCollection() {}
+  public function testCollection() {
+    $this->markTestSkipped('Irrelevant for this test');
+  }
 
   /**
    * {@inheritdoc}
-   *
-   * @requires module irrelevant_for_this_test
    */
-  public function testRelationships() {}
+  public function testRelationships() {
+    $this->markTestSkipped('Irrelevant for this test');
+  }
 
   /**
    * {@inheritdoc}
diff --git a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
index a9587313c74c..01260b2c85e7 100644
--- a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
@@ -10,6 +10,7 @@
 /**
  * @group Test
  * @group FunctionalTests
+ * @group legacy
  *
  * @coversDefaultClass \Drupal\Tests\BrowserTestBase
  */
@@ -25,6 +26,7 @@ class BrowserTestBaseTest extends KernelTestBase {
    * @covers ::checkModuleRequirements
    */
   public function testMethodRequiresModule() {
+    $this->expectDeprecation('Drupal\Tests\TestRequirementsTrait::checkModuleRequirements() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480');
     require __DIR__ . '/../../../../fixtures/BrowserMissingDependentModuleMethodTest.php';
 
     // @phpstan-ignore-next-line
@@ -53,6 +55,7 @@ public function testMethodRequiresModule() {
    * @covers ::checkModuleRequirements
    */
   public function testRequiresModule() {
+    $this->expectDeprecation('Drupal\Tests\TestRequirementsTrait::checkModuleRequirements() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480');
     require __DIR__ . '/../../../../fixtures/BrowserMissingDependentModuleTest.php';
 
     // @phpstan-ignore-next-line
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index d89d738e38d8..ce3d4318c89c 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -539,7 +539,7 @@ private function getExtensionsForModules(array $modules) {
     $list = $discovery->scan('module');
     foreach ($modules as $name) {
       if (!isset($list[$name])) {
-        throw new Exception("Unavailable module: '$name'. If this module needs to be downloaded separately, annotate the test class with '@requires module $name'.");
+        throw new Exception("Unavailable module: '$name'. If this module needs to be downloaded for testing, include it in the 'require-dev' section of your composer.json file.");
       }
       $extensions[$name] = $list[$name];
     }
diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
index f101af29df8e..192fee3f3547 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -281,8 +281,12 @@ public function testLocalTimeZone() {
    *
    * @covers ::checkRequirements
    * @covers ::checkModuleRequirements
+   *
+   * @group legacy
    */
   public function testMethodRequiresModule() {
+    $this->expectDeprecation('Drupal\Tests\TestRequirementsTrait::checkModuleRequirements() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480');
+
     require __DIR__ . '/../../fixtures/KernelMissingDependentModuleMethodTest.php';
 
     // @phpstan-ignore-next-line
@@ -309,8 +313,12 @@ public function testMethodRequiresModule() {
    *
    * @covers ::checkRequirements
    * @covers ::checkModuleRequirements
+   *
+   * @group legacy
    */
   public function testRequiresModule() {
+    $this->expectDeprecation('Drupal\Tests\TestRequirementsTrait::checkModuleRequirements() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480');
+
     require __DIR__ . '/../../fixtures/KernelMissingDependentModuleTest.php';
 
     // @phpstan-ignore-next-line
diff --git a/core/tests/Drupal/Tests/TestRequirementsTrait.php b/core/tests/Drupal/Tests/TestRequirementsTrait.php
index 8dae05cf3789..9cded2ee8755 100644
--- a/core/tests/Drupal/Tests/TestRequirementsTrait.php
+++ b/core/tests/Drupal/Tests/TestRequirementsTrait.php
@@ -35,8 +35,15 @@ protected static function getDrupalRoot() {
    * @throws \PHPUnit\Framework\SkippedTestError
    *   Thrown when the requirements are not met, and this test should be
    *   skipped. Callers should not catch this exception.
+   *
+   * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is
+   *   no replacement.
+   *
+   * @see https://www.drupal.org/node/3418480
    */
   protected function checkRequirements() {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480', E_USER_DEPRECATED);
+
     if (!$this->getName(FALSE) || !method_exists($this, $this->getName(FALSE))) {
       return;
     }
@@ -80,8 +87,15 @@ protected function checkRequirements() {
    * @throws \PHPUnit\Framework\SkippedTestError
    *   Thrown when the requirements are not met, and this test should be
    *   skipped. Callers should not catch this exception.
+   *
+   * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is
+   *   no replacement.
+   *
+   * @see https://www.drupal.org/node/3418480
    */
   private function checkModuleRequirements($root, array $annotations) {
+    @trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480', E_USER_DEPRECATED);
+
     // Make a list of required modules.
     $required_modules = [];
     foreach ($annotations as $requirement) {
diff --git a/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php b/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php
index bbf56501e832..09a637d74c33 100644
--- a/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php
+++ b/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php
@@ -4,6 +4,8 @@
 
 use Drupal\Tests\BrowserTestBase;
 
+@trigger_error('\\Drupal\\FunctionalTests\\BrowserMissingDependentModuleMethodTest is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480', E_USER_DEPRECATED);
+
 /**
  * A fixture test class with requires annotation.
  *
@@ -13,6 +15,11 @@
  * This test class should not be discovered by run-tests.sh, phpstan or phpunit.
  *
  * @group fixture
+ *
+ * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no
+ *   replacement.
+ *
+ * @see https://www.drupal.org/node/3418480
  */
 class BrowserMissingDependentModuleMethodTest extends BrowserTestBase {
 
diff --git a/core/tests/fixtures/BrowserMissingDependentModuleTest.php b/core/tests/fixtures/BrowserMissingDependentModuleTest.php
index 3a443746b176..40d8b370f643 100644
--- a/core/tests/fixtures/BrowserMissingDependentModuleTest.php
+++ b/core/tests/fixtures/BrowserMissingDependentModuleTest.php
@@ -4,6 +4,8 @@
 
 use Drupal\Tests\BrowserTestBase;
 
+@trigger_error('\\Drupal\\FunctionalTests\\BrowserMissingDependentModuleTest is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480', E_USER_DEPRECATED);
+
 /**
  * A fixture test class with requires annotation.
  *
@@ -14,6 +16,11 @@
  *
  * @requires module module_does_not_exist
  * @group fixture
+ *
+ * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no
+ *   replacement.
+ *
+ * @see https://www.drupal.org/node/3418480
  */
 class BrowserMissingDependentModuleTest extends BrowserTestBase {
 
diff --git a/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php b/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php
index 80f69c32a9ee..55d4a4e47234 100644
--- a/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php
+++ b/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php
@@ -2,6 +2,8 @@
 
 namespace Drupal\KernelTests;
 
+@trigger_error('\\Drupal\\FunctionalTests\\KernelMissingDependentModuleMethodTest is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480', E_USER_DEPRECATED);
+
 /**
  * A fixture test class with requires annotation.
  *
@@ -11,6 +13,11 @@
  * This test class should not be discovered by run-tests.sh, phpstan or phpunit.
  *
  * @group fixture
+ *
+ * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no
+ *   replacement.
+ *
+ * @see https://www.drupal.org/node/3418480
  */
 class KernelMissingDependentModuleMethodTest extends KernelTestBase {
 
diff --git a/core/tests/fixtures/KernelMissingDependentModuleTest.php b/core/tests/fixtures/KernelMissingDependentModuleTest.php
index 9fc372c03b58..7abc5e733f78 100644
--- a/core/tests/fixtures/KernelMissingDependentModuleTest.php
+++ b/core/tests/fixtures/KernelMissingDependentModuleTest.php
@@ -2,6 +2,8 @@
 
 namespace Drupal\KernelTests;
 
+@trigger_error('\\Drupal\\FunctionalTests\\KernelMissingDependentModuleTest is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480', E_USER_DEPRECATED);
+
 /**
  * A fixture test class with requires annotation.
  *
@@ -12,6 +14,11 @@
  *
  * @requires module module_does_not_exist
  * @group fixture
+ *
+ * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no
+ *   replacement.
+ *
+ * @see https://www.drupal.org/node/3418480
  */
 class KernelMissingDependentModuleTest extends KernelTestBase {
 
-- 
GitLab