During normal site operation, namespaces of disabled modules are not registered with the autoloader. This means if a module tries to instantiate a class provided by a disabled module, an error is (correctly) thrown.

However, during testing, simpletest.module registers the namespaces of all disabled modules in order to find their tests. This means that if a module has the error mentioned above, then it will not be discovered by the test.

In #1780396-54: Namespaces of disabled modules are registered during test runs, @Berdir suggested to fix this by limiting simpletest to only register the Tests subnamespace of each module. However, in that issue, @sun raised concerns about that making unit test writing too cumbersome (since in unit tests, there's no concept of enabling modules).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

effulgentsia’s picture

Status: Active » Needs review
FileSize
1.6 KB

#1780396-36: Namespaces of disabled modules are registered during test runs (the latest patch in that issue) has many hunks that no longer apply. This patch just takes the key hunk from that patch. It will likely fail, since it doesn't include all the other hunks.

effulgentsia’s picture

+++ b/core/vendor/phpunit/phpunit/PHPUnit/Util/Configuration.php
@@ -807,7 +807,7 @@ protected function getTestSuite(DOMElement $testSuiteNode, $testSuiteFilter=null
-            $exclude[] = (string)$excludeNode->nodeValue;
+            $exclude[] = $this->toAbsolutePath((string)$excludeNode->nodeValue);

This hack was necessary to make the exclude directives in core/phpunit.xml.dist actually work. Without that, PHPUnit tries to load classes that aren't actually tests, causing #1 to fail before even running any tests. If someone knows the correct way to fix that (i.e., without hacking PHPUnit), please share.

Status: Needs review » Needs work

The last submitted patch, simpletest-2006476-1.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

s/this/that/

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Version: 8.5.x-dev » 8.6.x-dev
Issue summary: View changes
Status: Needs work » Needs review
Related issues: +#2945465: Make TestDiscovery find info we need, not info we don't need
FileSize
1.8 KB

In run-tests.sh, simpletest_script_init() always creates a TestRunnerKernel, which sets up enough services so that we can store test results to a database. TRK needs the simpletest module, and says this: $this->getContainer()->get('test_discovery')->registerTestNamespaces(); which autoloads all the namespaces.

run-tests.sh then makes a child proc and calls itself with --execute-test which is a special mode to only run the test and not do discovery. If the test is a WTB test, then it runs, so all the extraneous classes are autoloadable. But if it's a PHPUnit-based test, it eventually reaches simpletest.module::simpletest_phpunit_run_command(), which calls exec() to run the phpunit test runner, and that's isolated from the autoloading present in under run-tests.sh.

Under PHPUnit, we do some special-case class loading in core/tests/bootstrap.php::drupal_phpunit_get_extension_namespaces(). This only loads the test namespaces you'd expect for core and extensions. Later, when we get to the BrowserTestBase layer, we end up autoloading for uninstalled modules. That's because BTB uses TestRunnerKernel as the kernel under test. KernelTestBase does not use TestRunnerKernel, so it doesn't suffer this fate.

So if the goal is to disallow autoloading of uninstalled or unneeded modules, then the first place to look is TestRunnerKernel and it's reliance on simpletest and TestDiscovery, since TestDiscovery::registerTestNamespaces() is where all this extra autoloading is enabled.

We should figure out how to perform test discovery and autoloading without 'enabling' any modules, including simpletest. And that's why this issue is related to #2945465: Make TestDiscovery find info we need, not info we don't need

Here are some tests which show that functional tests autoload simpletest module when they don't need to, and that other PHPUnit-based tests don't.

Status: Needs review » Needs work

The last submitted patch, 9: 2006476_9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nevergone’s picture

Related contrib project:
https://www.drupal.org/project/tecla

Mile23’s picture

Component: simpletest.module » phpunit

Updates to #9: Simpletest isn't in core any more, so therefore it is not enabled. :-) CR: https://www.drupal.org/node/3112907

The road to a solution still lives in TestRunnerKernel.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.