Implement @requires and @dependencies within TestBase, mark tests as skipped

Created on 8 September 2011, almost 13 years ago
Updated 6 February 2024, 5 months ago

Motivation

This is a followup to #1271060: Allow tests to declare 'requirements', skip tests where requirements are not met → . There is still a need for tests to be able to define requirements. However, as discussed on irc, it is still necessary to show failed tests (and allow them to run and show a failed status).

Currently, TestDiscovery::getTestClasses() checks the annotations of all test classes and rejects tests which have @requires module or @dependencies for modules which do not exist on the filesystem.

This behavior has tests in the existing codebase, so it is supported and should be maintained.

This behavior should not be the responsibility of TestDiscovery. It should be the behavior of the test class itself, which can mark the test as skipped. This way, the user can better understand why a test did not run.

This behavior is being moved to the test classes for PHPUnit-based tests in 📌 Explicitly skip @requires module in PHPUnit Kernel and Browser tests Fixed

We should move the behavior for Simpletest-based tests to \Drupal\simpletest\TestBase in this issue.

TestBase already has a checkRequirements() method. This allows test classes to do whatever they want WRT requirements. However, this does not allow for annotations.

Proposed Resolution

Create a patch that does the following on a given test class:

  • Check the annotated requirements
  • If there are any missing requirements, list them and mark the test as skipped. Otherwise, continue on and run the tests.

Annotation requirements checks should follow the same API as TestBase::checkRequirements(), returning an array with messages about missing requirements.

Also, this check can not occur in TestBase::checkRequirements() because subclasses can override and might not call the parent method.

So a new method should be created which can determine the requirements based on annotation. In order to avoid adding features to Simpletest (which is essentially in maintenance-only mode), this method will be final and private, so that it's the only code which defines how Simpletest interacts with annotations, and is not an API addition. See PHPUnit initiative: #2807237: PHPUnit initiative →

API Additions

None.

Remaining Tasks

📌 Task
Status

Closed: outdated

Version

11.0 🔥

Component
PHPUnit  →

Last updated about 15 hours ago

Created by

🇺🇸United States BTMash

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot → tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide → to find step-by-step guides for working with issues.

  • Status changed to Closed: outdated 5 months ago
  • 🇮🇹Italy mondrake 🇮🇹

    With PHPUnit 10 getting extremely strict about the use of annotations to only those they support, this is pretty much outdated now.

Production build 0.69.0 2024