Issue #3405353 by mondrake, neclimdul, smustgrave: Convert use of TestCase::getName() to forward compatible TestCase::name()

merge-requests/5631/merge
catch 2024-02-14 11:05:15 +00:00
parent 54a8e1befa
commit 4c6cd6e343
10 changed files with 28 additions and 9 deletions

View File

@ -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.");
}

View File

@ -80,7 +80,7 @@ abstract class MigrateSourceTestBase extends KernelTestBase {
protected function getPluginClass() {
$annotations = Test::parseTestMethodAnnotations(
static::class,
$this->getName()
$this->name()
);
if (isset($annotations['class']['covers'])) {

View File

@ -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.");
}

View File

@ -160,7 +160,7 @@ abstract class BuildTestBase extends TestCase {
// 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();

View File

@ -9,4 +9,11 @@ namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit9;
*/
trait TestCompatibilityTrait {
/**
* Get test name.
*/
public function name(): string {
return $this->getName();
}
}

View File

@ -59,7 +59,7 @@ class ComposerHookTest extends BuildTestBase {
$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);
}

View File

@ -8,6 +8,7 @@ use Composer\Util\Filesystem;
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 @@ use PHPUnit\Framework\TestCase;
class ManageGitIgnoreTest extends TestCase {
use ExecTrait;
use AssertUtilsTrait;
use PhpUnitCompatibilityTrait;
/**
* The root of this project.
@ -83,7 +85,7 @@ class ManageGitIgnoreTest extends TestCase {
* 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);

View File

@ -8,6 +8,7 @@ use Composer\Util\Filesystem;
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 @@ use PHPUnit\Framework\TestCase;
*/
class ScaffoldTest extends TestCase {
use AssertUtilsTrait;
use PhpUnitCompatibilityTrait;
/**
* The root of this project.
@ -65,7 +67,7 @@ class ScaffoldTest extends TestCase {
// 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());
}
}

View File

@ -8,6 +8,7 @@ use Composer\Util\Filesystem;
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 @@ class ScaffoldUpgradeTest extends TestCase {
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';

View File

@ -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;
}
}