Problem/Motivation

Bet you didn't know DrupalKernel has Simpletest in it.

DrupalKernel::bootEnvironment() says this:

    // Indicate that code is operating in a test child site.
    if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
      if ($test_prefix = drupal_valid_test_ua()) {
        $test_db = new TestDatabase($test_prefix);
        // Only code that interfaces directly with tests should rely on this
        // constant; e.g., the error/exception handler conditionally adds further
        // error information into HTTP response headers that are consumed by
        // Simpletest's internal browser.
        define('DRUPAL_TEST_IN_CHILD_SITE', TRUE);

        // Web tests are to be conducted with runtime assertions active.
        assert_options(ASSERT_ACTIVE, TRUE);
        // Now synchronize PHP 5 and 7's handling of assertions as much as
        // possible.
        Handle::register();

        // Log fatal errors to the test site directory.
        ini_set('log_errors', 1);
        ini_set('error_log', $app_root . '/' . $test_db->getTestSitePath() . '/error.log');

        // Ensure that a rewritten settings.php is used if opcache is on.
        ini_set('opcache.validate_timestamps', 'on');
        ini_set('opcache.revalidate_freq', 0);
      }
      else {
        // Ensure that no other code defines this.
        define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
      }
    }

This code fragment exists so that we can test WebTestBase.

When we eventually deprecate TestBase/WebTestBase, we won't be able to deprecate DrupalKernel::bootEnvironment().

Proposed resolution

Factor this code out of bootEnvironment() and into a separate static method which can be deprecated.

Deprecate the new method.

Somehow formally deprecate usages of DRUPAL_TEST_IN_CHILD_SITE which exists solely to isolate TestBase and WebTestBase from themselves during testing.

Remaining tasks

Figure out how to deprecate drupal_valid_test_ua() and friends.

User interface changes

API changes

Data model changes

Comments

Mile23 created an issue. See original summary.

mile23’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.5 KB

Something like this.

Status: Needs review » Needs work

The last submitted patch, 2: 2969741_2.patch, failed testing. View results

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new1.6 KB

Reroll.

Some of the fails in #2 fail locally for 8.6.x, so I'm curious to see what happens here.

mile23’s picture

StatusFileSize
new2.7 KB
new2.16 KB

Injecting the app root.

The last submitted patch, 4: 2969741_4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mile23’s picture

Title: Isolate simpletest within DrupalKernel (DRUPAL_TEST_IN_CHILD_SITE) » Deprecate simpletest within DrupalKernel (DRUPAL_TEST_IN_CHILD_SITE)
Issue summary: View changes
Issue tags: +Needs change record, +Needs issue summary update, +@deprecated
StatusFileSize
new2.93 KB
new1.24 KB

I honestly though there would be fails in #5.

Method docblock cleanup and CS fix.

Added @deprecated to the docblock. We're not ready to trigger a deprecation error by any means, since this called on every DrupalKernel::bootEnvironment() call. Added a @todo for that eventually. We'll need a follow-up if this is the way to go.

Adding 'needs CR' tag, but holding off on authoring it until there's some consensus.

Updating IS with a little bit of scope shift, because we should just go ahead and mark this method as deprecated.

mile23’s picture

lendude’s picture

Bet you didn't know DrupalKernel has Simpletest in it.

@Mile23++

+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -1004,6 +1004,34 @@ public static function bootEnvironment($app_root = NULL) {
+  protected static function bootEnvironmentForTestChildSite($app_root) {

Instead of trigger_error should this just be a private method and deprecated? That way nobody outside core can ever use it and adding a trigger_error to notify users outside of core is not needed. Doing a trigger error here just sounds weird, the moment we remove the call to the method from core, we also remove the only use of the method anywhere, so what would be the point of raising the error.

+++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
@@ -172,6 +172,7 @@ public static function getSkippedDeprecations() {
+      'Passing a Session object to the ExpectationException constructor is deprecated as of Mink 1.7. Pass the driver instead.',

why is this needed? It seems like this is just reshuffling code. Am I missing something?

mile23’s picture

Issue tags: -Needs change record
StatusFileSize
new1.93 KB
new2.25 KB

Thanks.

This patch turns the new method into a private one.

Added a CR, with @see in the docblock.

The skipped deprecation slipped in by accident.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

Nice. Lets see what others think.

dawehner’s picture

I'm quite confused about this issue. This is needed for BrowserTestBase and Nightwatch based testing. It is the way how we separate requests from the main and child sites.

lendude’s picture

Status: Reviewed & tested by the community » Needs review

@dawehner I saw some explicit checks for DRUPAL_TEST_IN_CHILD_SITE in Webtestbase et al. but not in BrowserTestBase or anything else. But looking at it in some more detail, you are right, it does seem to be a bit more wide spread in its use. So if we want to get rid of this, we should handle the existing dependencies too, I guess.

dawehner’s picture

Status: Needs review » Needs work

I guess "needs work" is a bit more specific :)

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.

MerryHamster’s picture

StatusFileSize
new1.93 KB

only reroll #10 patch for 8.7.x

MerryHamster’s picture

Status: Needs work » Needs review

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.

voleger’s picture

We have some progress in deprecation of the drupal_valid_test_ua() related functions #3038513: Move drupal_generate_test_ua() into the test system

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.

alexpott’s picture

Status: Needs review » Closed (works as designed)

I agree with #12. DRUPAL_TEST_IN_CHILD_SITE is used for testing not just Simpletest and the removal of Simpletest is not enough to remove it. This is the system working as designed.