Problem/Motivation

i'm a bit confused about the namespace overlap of \Drupal\Tests\TestSuites\TestSuiteBase and \Drupal\Tests\TestSuites\TestSuiteBaseTest

core/tests/TestSuites/TestSuiteBase.php
and core/tests/Drupal/Tests/TestSuites/TestSuiteBaseTest.php have the same namespace, but are living in total different folders.

On top of that \Drupal\Tests\TestSuites\TestSuiteBaseTest relies on core/tests/TestSuites/TestSuiteBase.php being loaded before.

Proposed resolution

  • Move the TestSuite files from \Drupal\Tests\TestSuites to \Drupal\TestSuites
  • Add a manual require_once into \Drupal\Tests\TestSuites\TestSuiteBaseTest

Remaining tasks

User interface changes

API changes

Data model changes

Comments

dawehner created an issue. See original summary.

mile23’s picture

Status: Active » Closed (duplicate)
Related issues: +#2794715: TestSuiteBaseTest cannot be executed as standalone test

Marking this as a duplicate of #2794715: TestSuiteBaseTest cannot be executed as standalone test since it's two errors requiring the same solution. If we decide something else there, we can re-open here.

mile23’s picture

Status: Closed (duplicate) » Needs review
StatusFileSize
new6.2 KB

In #2794715-10: TestSuiteBaseTest cannot be executed as standalone test it was decided that the solution to this issue would be too disruptive for 8.2.x, so if we're going to move files around in namespaces we should do that for 8.3.x.

Here's the patch from #5 in that issue. It will likely need to be re-rolled after that issue is committed.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

This solution is still super nice!

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

Thanks @Mile23; I agree with splitting the changes this way. I think a change record for this change would probably be good?

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new6.35 KB
new599 bytes

OK so this patch moves the test suite classes to \Drupal\TestSuites\* and has the test in \Drupal\Tests\TestSuites\TestSuiteBaseTest.

It changes the test so that it doesn't need require_once as per #2794715: TestSuiteBaseTest cannot be executed as standalone test

We can still run TestSuiteBaseTest as a single test:

$ ./vendor/bin/phpunit -c core/ --filter TestSuiteBaseTest
PHPUnit 4.8.11 by Sebastian Bergmann and contributors.

..

Time: 20.2 seconds, Memory: 86.00Mb

OK (2 tests, 4 assertions)

Change record coming up. We should have made a change record for #2499239: Use test suite classes to discover different test types under phpunit, allow contrib harmony with run-tests so I'll include that.

dawehner’s picture

Still like this fix :)

We still need some change record :)

mile23’s picture

Someone asked for a change record? https://www.drupal.org/node/2799437

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record

Thanks a ton!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 2781203_6.patch, failed testing.

mile23’s picture

Status: Needs work » Reviewed & tested by the community

Failed test is FeedAdminDisplayTest, which I'm willing to bet is unrelated. Resetting to RTBC and restarting testbot.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/Tests/TestSuites/TestSuiteBaseTest.php
@@ -2,14 +2,11 @@
-// The test suite class is not part of the autoloader, we need to include it
-// manually.
-require_once __DIR__ . '/../../../TestSuites/TestSuiteBase.php';

+++ b/core/tests/bootstrap.php
@@ -117,6 +117,7 @@ function drupal_phpunit_populate_class_loader() {
+  $loader->add('Drupal\\TestSuites', __DIR__);

We need to be changing the autoloader less under testing not more. The test suite classes have no need to be autoloaded.

klausi’s picture

Agreed, can we just move the test suite classes to core/tests/Drupal/Tests?

I know the test suites are not unit tests, but that way we avoid modifying the auto loader yet again and can still remove the require_once statements.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new6.68 KB
new2.64 KB

can we just move the test suite classes to core/tests/Drupal/Tests

Not sure why that's needed. @alexpott is talking about not allowing autoloading for the test suites *at all.* It's a good ideal.

klausi’s picture

Status: Needs review » Needs work
+++ b/core/tests/bootstrap.php
@@ -117,6 +117,7 @@ function drupal_phpunit_populate_class_loader() {
   $loader->add('Drupal\\KernelTests', __DIR__);
   $loader->add('Drupal\\FunctionalTests', __DIR__);
   $loader->add('Drupal\\FunctionalJavascriptTests', __DIR__);
+  $loader->add('Drupal\\TestSuites', __DIR__);

so this line should not be added?

I find this require_once hackery in all the classes annoying. Any Drupal contrib module that wants to use TestSuiteBase has to do some require_once weirdness yet again :(

alexpott’s picture

TestSuiteBase is not an extension point. How exactly is a contrib module going to use TestSuiteBase?

alexpott’s picture

@klausi the line should not be added because changing the autoloader because of the test system is wrong. The autoloader should match the environment without the test system in play.

mile23’s picture

Status: Needs work » Needs review

Ewps... Missed changing that one line in bootstrap for the last patch.

As for contrib using the suite classes.. I'm not sure what the use-case is. I'd really rather see more of core use these, though, for uses like the UI runner. If that need arises, we can maybe just change it back.

mile23’s picture

StatusFileSize
new6.14 KB
new554 bytes

The autoloader should match the environment without the test system in play.

If that's the case, then there's a logical follow-up to modify bootstrap.php to not change the autoloader. But, you know... good luck. :-) We have to discover extension tests in arbitrary locations.

Status: Needs review » Needs work

The last submitted patch, 19: 2781203_18.patch, failed testing.

mile23’s picture

Status: Needs work » Needs review

Restarting test after CI error.

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch no longer applies. It looks very good though and has been rtbc 3 times already.

mile23’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new9.89 KB
new4.37 KB

Reroll.

Also, the require_once would mean that the class was hanging around for all subsequent tests, so I refactored TestSuiteBaseTest a little to use a mock instead of a subclass, and added @runTestsInSeparateProcesses.

Status: Needs review » Needs work

The last submitted patch, 26: 2781203_26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new10.24 KB
new862 bytes

OK, so if we isolate the test system from the system under test, then the test listener can't find TestSuiteBase for @coversDefaultClass, as the fail in #26 shows:

Drupal\Tests\Core\Test\TestSuiteBaseTest::testAddTestsBySuiteNamespaceCore with data set "unit-tests" (array(array(array(), array(), array(array(array('<?php'), array('<?php', array('<?php', array('<?php'))))))), 'Unit', array('vfs://root/core/tests/Drupal/...st.php'))
@coversDefaultClass does not exist '\Drupal\TestSuites\TestSuiteBase': Drupal\Tests\Core\Test\TestSuiteBaseTest::testAddTestsBySuiteNamespaceCore with data set "unit-tests"

This tests passes locally for me because I use --testsuite unit to run it, which loads TestSuiteBase in order to do discovery.

Keeping the classloader isolation seems to be an important restriction from #16 and #17, so we'll remove @coversDefaultClass/@covers and turn them into documentation.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

#28 and the reasons for removing @covers sounds like a super solid idea.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/phpunit.xml.dist
@@ -37,16 +37,16 @@
-      <file>./tests/TestSuites/UnitTestSuite.php</file>
+      <file>./tests/Drupal/TestSuites/UnitTestSuite.php</file>

Won't these changes break everyone's customised phpunit.xml files? I think we shouldn't make this change in this way.

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.

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.

smustgrave’s picture

Status: Needs review » Needs work

Agree with @alexpott this will break local uniting testing.

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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

dcam’s picture

Status: Needs work » Closed (outdated)

Test suites were dropped from PHPUnit 10. We deprecated them during the Drupal 10 cycle and removed from Drupal 11, CR: https://www.drupal.org/node/3405829. TestSuiteBaseTest still exists, but no longer has the include statement because the target class was deleted. Closing as outdated.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

dcam’s picture

Issue tags: +stale-issue-cleanup