Problem/Motivation
See https://git.drupalcode.org/project/drupal/-/blob/main/core/lib/Drupal/Co... for a bit of prior art.
Long story short: DrupalApplication doesn't call DrupalKernel::bootEnvironment() which, among other things, sets up the awkward DRUPAL_TEST_IN_CHILD_SITE constant.
Result: if you run a command in a test, and that command runs some code that interrogates the DRUPAL_TEST_IN_CHILD_SITE constant, it craps out with a fatal error because you've tried to access an undefined constant.
Proposed resolution
Option 1: Split out the part of bootEnvironment() responsible for DRUPAL_TEST_IN_CHILD_SITE to a new method
MR !16037
- Add a new public (but @internal) DrupalKernel::setupDrupalTestInChildSite() method.
- Move all the code from
DrupalKernel::bootEnvironment()that deals withDRUPAL_TEST_IN_CHILD_SITEinto that. - Call it from both
DrupalKernel::bootEnvironment()andDrupalApplication::bootstrap().
Option 2: Add a flag to bootEnvironment() to not change the error handler
MR !16039
- Add a new optional $set_error_handler flag (defaults to
TRUE) toDrupalKernel::bootEnvironment(). - Only set the Drupal error handler if this flag is
TRUE. - Call
DrupalKernel::bootEnvironment()fromDrupalApplication::bootstrap()with the flag set toFALSE. - Remove @todo comment about not calling
bootEnvironment().
Issue fork drupal-3597692
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dwwYup, another good find. Thanks for opening this!
Comment #4
dwwSeems like we should start the work of #2690035: Extract DrupalKernel::bootEnvironment into SAPI adapter and move the
DRUPAL_TEST_IN_CHILD_SITEblock inDrupalKernel::bootEnvironment()to a static helper method, and call it from bothbootEnvironment()andDrupalApplication.Comment #6
dwwSomething like that?
Comment #7
phenaproximaThis fully solves the problem for Drupal CMS. My feeling: land it now before 11.4 to avoid breaking folks who might run into this, refactor later.
Comment #9
kingdutch+1 on RTBC based on 16037
16039 is interesting, but makes it more complex to get rid of the
$app_rootargument frombootEnvironmentbased on the extra optional argument.At least to me it makes eliminating
bootEnvironment(or the contents ofsetupDrupalTestInChildSite) more complex, because making sure the logic is moved around is no longer enough and we now have an additional branch we need to figure out when refactoring.Comment #10
dwwThanks for the review Kingdutch! Agreed on all points. Pushed a commit to apply the suggestions, and fully make
$app_rootrequired (update docs). Also pushed a commit to markDrupalKernel::setupDrupalTestInChildSite()@internaleven though it'spublic. Pipeline is still green.However, also considered another possible solution here. Is MR!16039 better? No new method (just a new optional flag to
DrupalKernel::bootEnvironment()) and now we can call it fromDrupalApplication. Removes a @todo and @see.Updated the summary with both options for proposed resolution.
Back to NR, although either MR could be RTBC at this point.
Comment #11
dwwRestoring RTBC for MR 16037. Leaving 16039 up for committer discretion.
Comment #12
dwwFor clarity, when I wrote comment #10, comment #9 only said "+1 on RTBC". 😅 So I was only agreeing on "all points" from the review of 16037. After I posted #10, #9 was edited to compare the 2 MRs.
I think 16037 is probably better, and that's the one phenaproxima has already tested and confirmed.
Comment #13
kingdutchYeah, when I wrote +1 on RTBC I only saw one MR 😜 so edited to clarify 🤝
Edit: typo
Comment #18
godotislateCommitted changes from MR 16037 and and pushed 7554740 to main, and bd16975 to 11.x. Thanks!
Since we are in RC period, will need to check with other RMs about whether this can be backported to 11.4. Setting to Patch (to be ported) for now.
Comment #20
godotislateSpoke with @longwave on Slack, and this is good for 11.4.
Comment #23
dwwThanks! Relieved to see this in all the relevant branches.