Issue #3418379 by mondrake, Spokje: Deprecate Drupal\Tests\TestRequirementsTrait::checkRequirements and ::checkModuleRequirements

merge-requests/6433/head
Dave Long 2024-02-02 11:26:12 +00:00
parent d67efd4301
commit 614ff9d255
No known key found for this signature in database
GPG Key ID: ED52AE211E142771
9 changed files with 72 additions and 19 deletions

View File

@ -147,45 +147,45 @@ class FileUploadTest extends ResourceTestBase {
/**
* {@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}

View File

@ -10,6 +10,7 @@ use PHPUnit\Framework\SkippedTestError;
/**
* @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 @@ class BrowserTestBaseTest extends KernelTestBase {
* @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

View File

@ -539,7 +539,7 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
$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];
}

View File

@ -281,8 +281,12 @@ class KernelTestBaseTest extends KernelTestBase {
*
* @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 @@ class KernelTestBaseTest extends KernelTestBase {
*
* @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

View File

@ -35,8 +35,15 @@ trait TestRequirementsTrait {
* @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 @@ trait TestRequirementsTrait {
* @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) {

View File

@ -4,6 +4,8 @@ namespace Drupal\FunctionalTests;
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 @@ use Drupal\Tests\BrowserTestBase;
* 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 {

View File

@ -4,6 +4,8 @@ namespace Drupal\FunctionalTests;
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 @@ use Drupal\Tests\BrowserTestBase;
*
* @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 {

View File

@ -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 @@ namespace Drupal\KernelTests;
* 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 {

View File

@ -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 @@ namespace Drupal\KernelTests;
*
* @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 {