Problem/Motivation

The TestRunnerKernel hardwires the module list to system and simpletest. Good luck implementing a hook in these circumstances.

We also want to deprecate the dependency between the testing system and the simpletest module: #2863044: [plan] Remove simpletest dependencies from PHPUnit-based tests

TestDiscovery has a dependency on the module handler only so that it can fire this hook. When this dependency is deprecated (in this issue) we can then work on #2863055: Move TestDiscovery out of simpletest module, minimize dependencies

Proposed resolution

Deprecate the hook for removal before Drupal 9. drivers get a chance in #2459745: Allow the database driver to skip test classes modules don't.

Remaining tasks

Remove invocations of this hook in Drupal 9.

User interface changes

None.

API changes

Deprecate hook_simpletest_alter().

Comments

dawehner’s picture

Well, you could really ask yourself wether the hook is the way to do it, given that it requires a proper parent site.

Given that the settings override in settings.testing.php seems great for me.

Note: Also #2304461: KernelTestBaseTNG™ and #2232861: Create BrowserTestBase for web-testing on top of Mink might make this harder than currently.

chx’s picture

Status: Active » Needs review
StatusFileSize
new1.88 KB

Here's one possible patch.

larowlan’s picture

+++ b/core/modules/simpletest/simpletest.api.php
@@ -13,6 +13,21 @@
+ * This will not from the command line without a settings.php in place
+ * containing a list of test modules:

This sentence doesn't make sense

Thought some more about the intent here - could we have a new annotation on test classes @unsupportedDrivers - which took an array of driver names, defaulting to none?

Then we could tag tests that weren't supported by a given driver.

chx’s picture

Yes, I missed the verb, would

This will work not from the command line without a settings.php in place containing a list of test modules:

work?

Regarding the annotation: that won't work -- you do not know the drivers ahead of the time. Like, the Oracle driver didn't even start a D8 version yet. And that's just the DB drivers -- efq_views might want to override what mongodb doesn't support for example. It needs to be a hook or similar.

Also, this solution allows for adding modules to the TestRunnerKernel which currently requires very ... ahem ... interesting code which I would rather not ship.

chx’s picture

Also, the driver issues is at #2459745: Allow the database driver to skip test classes and I feel it's a different issue to this.

chx’s picture

StatusFileSize
new2.04 KB

I've completely rewritten the doxygen.

chx’s picture

StatusFileSize
new2.28 KB

More cowbell! (Actually, comments in TestRunnerKernel)

dawehner’s picture

+++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php
@@ -51,8 +51,20 @@ public function __construct($environment, $class_loader) {
+      // If there are modules implementing hook_simpletest_alter then
+      // settings.php must exist and supply module data for modules
+      // implementing that hook.

As written in IRC it would be great to explain WHY those module data has to be provided ... this hook is executed outside of an installed drupal site, so you don't have the modules with the alter hook available in the first place.

chx’s picture

StatusFileSize
new2.41 KB

Another attempt.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

At the very least we're missing a pointer to this in hook_simpletest_alter.

But for me this approach doesn't feel right. i think we should not use alters for this at all. There should be only one way to achieve this and using hooks means that it'll work when you have a full drupal test runner but then you'll have to know to add this extra stuff to settings.php.

chx’s picture

Status: Needs work » Needs review

> At the very least we're missing a pointer to this in hook_simpletest_alter.

I do not quite understand. A pointer to what? All the new documentation is on hook_simpletest_alter.

And I am glad to accept better alternatives. List of callbacks in settings.php perhaps?

chx’s picture

Title: hook_simpletest_alter isn't working from CLI » Remove hook_simpletest_alter: it isn't working from CLI
Issue summary: View changes
moshe weitzman’s picture

IMO it is valid for a hosting platform to ship with a module that skips certain tests. Similarly, a custom web site might skip Drupal core or contrib tests that it does not care about. Ideally we could specify individual classes to skip because skipping a whole module is reckless overkill Anyway, I just want to articulate use cases beyond DB drivers.

mgifford’s picture

StatusFileSize
new2.41 KB

Re-uploading patch for the bots.

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.

dawehner’s picture

I think we should let this later hook just die away. In phpunit you can ignore certain tests using https://stackoverflow.com/questions/22645986/phpunit-testsuite-exclude
so if you want to run the entire core test suite you could ignore the tests by writing your own phpunit.xml file.

mile23’s picture

mile23’s picture

Title: Remove hook_simpletest_alter: it isn't working from CLI » Deprecate hook_simpletest_alter: it isn't working from CLI
Version: 8.3.x-dev » 8.4.x-dev
Issue summary: View changes
Issue tags: +Needs change record, +Needs followup
StatusFileSize
new942 bytes

Changing to 8.4.x because it's disruptive.

Status: Needs review » Needs work

The last submitted patch, 21: 2460521_21.patch, failed testing.

mile23’s picture

Status: Needs work » Needs review

Testbot burp.

Status: Needs review » Needs work

The last submitted patch, 21: 2460521_21.patch, failed testing.

mile23’s picture

mile23’s picture

Status: Postponed » Needs review
StatusFileSize
new1.05 KB
new666 bytes

And, just like #2234479: Deprecate hook_test_* hooks in simpletest we can unpostpone because #2866779: Add a way to trigger_error() for deprecated hooks is now postponed because core doesn't actually deal with the trigger_error() yet.

Added @todo for #2866779: Add a way to trigger_error() for deprecated hooks

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Getting at least this information about is a good step.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Hook deprecation hasn't really been tackled in the deprecation policy but I think we should try and think about how it should be done. I think we need a followup to discuss this. Also there is no change record yet.

mile23’s picture

mile23’s picture

mile23’s picture

Status: Needs work » Postponed

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.

mile23’s picture

Status: Postponed » Needs work
Issue tags: +@deprecated

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.

mile23’s picture

Issue tags: -Needs change record, -Needs followup
StatusFileSize
new1.59 KB
new1.54 KB

Added change record.

I'm not sure what the follow-up was supposed to be.

Here's a patch against 8.6.x.

mile23’s picture

Status: Needs work » Needs review
mile23’s picture

Status: Needs review » Needs work
+++ b/core/modules/simpletest/simpletest.api.php
@@ -13,10 +13,16 @@
+ * This hook is only invoked by the Simpletest UI builder. It will not be
+ * invoked by run-tests.sh or the phpunit tool.

This isn't true. There are two reasons run-tests.sh needs simpletest module enabled: 1) TestDiscovery depends on ModuleHandler so it can fire this hook and, 2) Functions in simpletest.module. The hook is not fired from the PHPUnit tool so I got that right.

I was thinking of #2234479: Deprecate hook_test_* hooks in simpletest when I wrote that.

dawehner’s picture

@Mile23 Do you understand why this fails?

mile23’s picture

Status: Needs work » Needs review

It has a ton of these: "Drupal\Core\Database\DatabaseNotFoundException: SQLSTATE[HY000] [1049] Unknown database 'jenkins_drupal_patches_46060'"

That has always looked like a testbot failure to me.

Re-running.

mile23’s picture

StatusFileSize
new3.05 KB
new4.02 KB

It turns out it was a testbot failure.

Fixed the docblock and added a test.

mile23’s picture

Title: Deprecate hook_simpletest_alter: it isn't working from CLI » Deprecate hook_simpletest_alter()
Issue summary: View changes
Related issues: +#2863044: [plan] Remove simpletest dependencies from PHPUnit-based tests

Updated IS.

dawehner’s picture

@Mile23
Do you mind linking to the change record inside the code?

mile23’s picture

StatusFileSize
new4.06 KB
new584 bytes

Ah, good catch.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @Mile23!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

The deprecation message should contain a link to the change record. Since this allows us to keep the change record up-to-date with any additional info discovered after committing this.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new4.14 KB
new1.88 KB

Updated per #45

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 46: 2460521_46.patch, failed testing. View results

mile23’s picture

StatusFileSize
new4.13 KB
mile23’s picture

Status: Needs work » Needs review
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Still applies, was already RTBC in #47.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed d208812 and pushed to 8.6.x. Thanks!

In reference to #14 - one thing that I think we should try to state somewhere is that core's tests are for core. The idea of a site running them to see if it works is not a good one. There are tests that are designed to be extended like \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase but you don't need an alter hook for that.

  • alexpott committed d208812 on 8.6.x
    Issue #2460521 by Mile23, chx, mgifford, dawehner, larowlan: Deprecate...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.