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