From 4c6cd6e343bc18830b306e89b287b1a2c20d0ecd Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Wed, 14 Feb 2024 11:05:15 +0000
Subject: [PATCH] Issue #3405353 by mondrake, neclimdul, smustgrave: Convert
 use of TestCase::getName() to forward compatible TestCase::name()

---
 .../tests/src/Functional/ConfigEntityResourceTestBase.php | 2 +-
 .../migrate/tests/src/Kernel/MigrateSourceTestBase.php    | 2 +-
 .../EntityResource/ConfigEntityResourceTestBase.php       | 2 +-
 core/tests/Drupal/BuildTests/Framework/BuildTestBase.php  | 2 +-
 .../PhpUnit9/TestCompatibilityTrait.php                   | 7 +++++++
 .../Plugin/Scaffold/Functional/ComposerHookTest.php       | 2 +-
 .../Plugin/Scaffold/Functional/ManageGitIgnoreTest.php    | 4 +++-
 .../Composer/Plugin/Scaffold/Functional/ScaffoldTest.php  | 4 +++-
 .../Plugin/Scaffold/Functional/ScaffoldUpgradeTest.php    | 4 +++-
 core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php     | 8 +++++++-
 10 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/core/modules/jsonapi/tests/src/Functional/ConfigEntityResourceTestBase.php b/core/modules/jsonapi/tests/src/Functional/ConfigEntityResourceTestBase.php
index e80a96d40514..f1bad7ce3400 100644
--- a/core/modules/jsonapi/tests/src/Functional/ConfigEntityResourceTestBase.php
+++ b/core/modules/jsonapi/tests/src/Functional/ConfigEntityResourceTestBase.php
@@ -27,7 +27,7 @@ abstract class ConfigEntityResourceTestBase extends ResourceTestBase {
    * {@inheritdoc}
    */
   public function setUp(): void {
-    if (in_array($this->getName(), static::SKIP_METHODS, TRUE)) {
+    if (in_array($this->name(), static::SKIP_METHODS, TRUE)) {
       // Skip before installing Drupal to prevent unnecessary use of resources.
       $this->markTestSkipped("Not yet supported for config entities.");
     }
diff --git a/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php b/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php
index 0c351aac4bed..56f6db4bdf05 100644
--- a/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php
+++ b/core/modules/migrate/tests/src/Kernel/MigrateSourceTestBase.php
@@ -80,7 +80,7 @@ protected function setUp(): void {
   protected function getPluginClass() {
     $annotations = Test::parseTestMethodAnnotations(
       static::class,
-      $this->getName()
+      $this->name()
     );
 
     if (isset($annotations['class']['covers'])) {
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ConfigEntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ConfigEntityResourceTestBase.php
index 152b781de8c2..05609db738d4 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/ConfigEntityResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/ConfigEntityResourceTestBase.php
@@ -20,7 +20,7 @@ abstract class ConfigEntityResourceTestBase extends EntityResourceTestBase {
    * {@inheritdoc}
    */
   protected function setUp(): void {
-    if (in_array($this->getName(), static::SKIP_METHODS, TRUE)) {
+    if (in_array($this->name(), static::SKIP_METHODS, TRUE)) {
       // Skip before installing Drupal to prevent unnecessary use of resources.
       $this->markTestSkipped("Not yet supported for config entities.");
     }
diff --git a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
index 408143aeaa55..375517369823 100644
--- a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
+++ b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
@@ -160,7 +160,7 @@ protected function setUp(): void {
     // Set up the workspace directory.
     // @todo Glean working directory from env vars, etc.
     $fs = new SymfonyFilesystem();
-    $this->workspaceDir = $fs->tempnam(DrupalFilesystem::getOsTemporaryDirectory(), '/build_workspace_' . md5($this->getName() . microtime(TRUE)));
+    $this->workspaceDir = $fs->tempnam(DrupalFilesystem::getOsTemporaryDirectory(), '/build_workspace_' . md5($this->name() . microtime(TRUE)));
     $fs->remove($this->workspaceDir);
     $fs->mkdir($this->workspaceDir);
     $this->initMink();
diff --git a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit9/TestCompatibilityTrait.php b/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit9/TestCompatibilityTrait.php
index 4bb8b01e1945..8d647a5c7485 100644
--- a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit9/TestCompatibilityTrait.php
+++ b/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit9/TestCompatibilityTrait.php
@@ -9,4 +9,11 @@
  */
 trait TestCompatibilityTrait {
 
+  /**
+   * Get test name.
+   */
+  public function name(): string {
+    return $this->getName();
+  }
+
 }
diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ComposerHookTest.php b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ComposerHookTest.php
index 24fcdfce2982..1b2099f2e3a7 100644
--- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ComposerHookTest.php
+++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ComposerHookTest.php
@@ -59,7 +59,7 @@ protected function setUp(): void {
     $this->fileSystem = new Filesystem();
     $this->fixtures = new Fixtures();
     $this->fixtures->createIsolatedComposerCacheDir();
-    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
+    $this->fixturesDir = $this->fixtures->tmpDir($this->name());
     $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()];
     $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
   }
diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php
index 9e50d3c92bf0..c23631c7b548 100644
--- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php
+++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php
@@ -8,6 +8,7 @@
 use Drupal\Tests\Composer\Plugin\Scaffold\Fixtures;
 use Drupal\Tests\Composer\Plugin\Scaffold\AssertUtilsTrait;
 use Drupal\Tests\Composer\Plugin\Scaffold\ExecTrait;
+use Drupal\Tests\PhpUnitCompatibilityTrait;
 use PHPUnit\Framework\TestCase;
 
 /**
@@ -22,6 +23,7 @@
 class ManageGitIgnoreTest extends TestCase {
   use ExecTrait;
   use AssertUtilsTrait;
+  use PhpUnitCompatibilityTrait;
 
   /**
    * The root of this project.
@@ -83,7 +85,7 @@ protected function tearDown(): void {
    *   The path to the fixture directory.
    */
   protected function createSutWithGit($fixture_name) {
-    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
+    $this->fixturesDir = $this->fixtures->tmpDir($this->name());
     $sut = $this->fixturesDir . '/' . $fixture_name;
     $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->projectRoot];
     $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldTest.php b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldTest.php
index 8f3055f7ce2d..55ecf23c99c0 100644
--- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldTest.php
+++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldTest.php
@@ -8,6 +8,7 @@
 use Drupal\Tests\Composer\Plugin\Scaffold\AssertUtilsTrait;
 use Drupal\Tests\Composer\Plugin\Scaffold\Fixtures;
 use Drupal\Tests\Composer\Plugin\Scaffold\ScaffoldTestResult;
+use Drupal\Tests\PhpUnitCompatibilityTrait;
 use PHPUnit\Framework\TestCase;
 
 /**
@@ -20,6 +21,7 @@
  */
 class ScaffoldTest extends TestCase {
   use AssertUtilsTrait;
+  use PhpUnitCompatibilityTrait;
 
   /**
    * The root of this project.
@@ -65,7 +67,7 @@ protected function setUp(): void {
     // a directory will be created in the system's temporary directory.
     $this->fixturesDir = getenv('SCAFFOLD_FIXTURE_DIR');
     if (!$this->fixturesDir) {
-      $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
+      $this->fixturesDir = $this->fixtures->tmpDir($this->name());
     }
   }
 
diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldUpgradeTest.php b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldUpgradeTest.php
index 20eb6d1e5a1b..f28ec78ca510 100644
--- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldUpgradeTest.php
+++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ScaffoldUpgradeTest.php
@@ -8,6 +8,7 @@
 use Drupal\Tests\Composer\Plugin\Scaffold\AssertUtilsTrait;
 use Drupal\Tests\Composer\Plugin\Scaffold\ExecTrait;
 use Drupal\Tests\Composer\Plugin\Scaffold\Fixtures;
+use Drupal\Tests\PhpUnitCompatibilityTrait;
 use PHPUnit\Framework\TestCase;
 
 /**
@@ -27,6 +28,7 @@ class ScaffoldUpgradeTest extends TestCase {
 
   use AssertUtilsTrait;
   use ExecTrait;
+  use PhpUnitCompatibilityTrait;
 
   /**
    * The Fixtures object.
@@ -58,7 +60,7 @@ public function testScaffoldUpgrade() {
     if (str_contains($composerVersionLine, 'Composer version 2')) {
       $this->markTestSkipped('We cannot run the scaffold upgrade test with Composer 2 until we have a stable version of drupal/core-composer-scaffold to start from that we can install with Composer 2.x.');
     }
-    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
+    $this->fixturesDir = $this->fixtures->tmpDir($this->name());
     $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()];
     $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
     $topLevelProjectDir = 'drupal-drupal';
diff --git a/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php b/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php
index 3bba95e3a761..932bd03a3e83 100644
--- a/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php
+++ b/core/tests/Drupal/Tests/PhpUnitCompatibilityTrait.php
@@ -15,9 +15,15 @@ class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit" . RunnerVersion::get
 if (FALSE) {
 
   /**
-   * Makes Drupal's test API forward compatible with multiple versions of PHPUnit.
+   * Makes Drupal's test API forward compatible with future PHPUnit releases.
+   *
+   * This stub is present here to allow PHPStan identify the methods present
+   * in the version-bound trait.
    */
   trait PhpUnitCompatibilityTrait {
+
+    use \Drupal\TestTools\PhpUnitCompatibility\PhpUnit9\TestCompatibilityTrait;
+
   }
 
 }
-- 
GitLab