\Drupal\Tests\system\Functional\Module\VersionTest could be a Kernel (or Unit) Test

Created on 24 April 2019, over 6 years ago
Updated 30 June 2025, about 1 month ago

Problem/Motivation

\Drupal\Tests\system\Functional\Module\VersionTest can do with some modernisation, it makes 14 http requests to validate version constraints

Proposed resolution

Retain one functional test for the disabled checkboxes
Move the rest to a kernel or possibly unit test

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

base system

Created by

πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • First commit to issue fork.
  • Merge request !12542Issue #3050353: Initial refactor β†’ (Closed) created by mstrelan
  • Pipeline finished with Success
    about 1 month ago
    Total: 404s
    #534693
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    This was originally added 11 years ago in #211747: Allow specifying version information as part of module dependencies β†’ . I approached this first by doing the least possible to convert from a Functional test to a Kernel test.

    Before
    Time: 00:44.311, Memory: 12.00 MB

    After:
    Time: 00:00.909, Memory: 12.00 MB

    Before refactoring further I wonder if it's worth just committing this for the massive speed boost and then discussing the following.

    I think started investigating how it works and wish I had never seen this. The test has an array of dependency strings. Every odd numbered dependency is valid and every even numbered dependency is invalid. This is stored in state. There is a hook \Drupal\system_test\Hook\SystemTestHooks::systemInfoAlter that shifts the first constraint off the list and alters the info for the module_test module. The test then loops through the dependency strings, loads the modules form which invokes the hook, and checks if the checkbox to enable module_test is disabled or not.

    So I began to wonder what it is we're actually trying to test. Is this the syntax of the version strings? Is it that the checkbox is disabled for incompatible modules? In #3 @larowlan mentioned we could probably just add most of these to \Drupal\Tests\Component\Version\ConstraintTest::providerIsCompatible. But when I stepped through the code it seems it might be more appropriate to expand \Drupal\Tests\Core\Extension\DependencyTest::testIsCompatible. The test essentially boils down to the value of $incompatible in this snippet:

    // If this module requires other modules, add them to the array.
    /** @var \Drupal\Core\Extension\Dependency $dependency_object */
    foreach ($module->requires as $dependency => $dependency_object) {
      // @todo Add logic for not displaying hidden modules in
      //   https://drupal.org/node/3117829.
      if ($incompatible = $this->checkDependencyMessage($modules, $dependency, $dependency_object)) {
    
  • Pipeline finished with Failed
    about 1 month ago
    Total: 768s
    #534700
  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    I also tried using a provider but it's quite a lot slower:

    Time: 00:08.720, Memory: 12.00 MB
    

    So I've reverted that, but made some tweaks to remove some hacks like the static variable and the array_shift. It means state is only set in the test and not also in the hook, which makes it easier to understand the even/odd logic.

  • Pipeline finished with Success
    about 1 month ago
    Total: 1196s
    #534717
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Seems like a good refactor to me. Still asserting that things are disabled as before. See no issue.

    • catch β†’ committed 222d7506 on 11.x
      Issue #3050353 by mstrelan, larowlan: \Drupal\Tests\system\Functional\...
  • πŸ‡¬πŸ‡§United Kingdom catch

    This was originally added 11 years ago in #211747: Allow specifying version information as part of module dependencies.

    Had a quick look at the issue, I think it was actually added 16 years ago? Looks like the cvs commit happened in 2009.

    Let's definitely open a follow-up to discuss whether we should remove the test altogether or if it can be simplified further.

    Committed/pushed to 11.x, thanks!

  • πŸ‡¦πŸ‡ΊAustralia mstrelan

    You're right, it was 16 years ago, it was the last updated date on the issue that was 11 years ago.

    Follow up πŸ“Œ Decide the fate of Drupal\Tests\system\Kernel\Module\VersionTest Active

Production build 0.71.5 2024