Problem/Motivation
DrupalKernel::bootEnvironment is responsible for setting up some important values in global scope before the kernel is booted. This pre-boot setup must only be performed once throughout a request. However, the application kernel is instantiated and booted repeatedly during tests. In order to protect against reinitialization, bookEnvironment maintains a static flag on DrupalKernel.
Closer inspection of bootEnvironment suggests that a large part of the code only makes sense when running as web application. It looks like delegating the responsibility of bootEnvironment might make it easier to adapt DrupalKernel to execution environments other than web servers.
Proposed resolution
Extract DrupalKernel::bootEnvironment into a set of classes under the namespace \Drupal\Core\SAPI and separate code paths for CLI and web SAPIs.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | extract-2690035-37.patch | 80.85 KB | billywardrop |
| #34 | extract-2690035-34.patch | 79.64 KB | deepakaryan1988 |
| #31 | extract-2690035-31.patch | 72.87 KB | deepakaryan1988 |
| #28 | extract-2690035-28.patch | 80.07 KB | kostyashupenko |
| #26 | extract-2690035-26.patch | 32.83 KB | znerol |
Issue fork drupal-2690035
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 #2
znerol commentedComment #3
znerol commentedComment #5
znerol commentedComment #7
znerol commentedComment #8
znerol commentedComment #11
znerol commentedComment #12
dawehnerJust some quick feedback.
Is there a reason why we don't add assertions here?
This variable isn't used
Comment #14
znerol commented#11 was the wrong patch :/, interdiff is against #8.
Because we only turn assertions on at that early stage when running inside a web-test child site.
Right, let's use it.
Comment #16
znerol commentedComment #18
znerol commentedComment #19
znerol commented#18 contains changes I did not intend to publish... this should be better, interdiff is against #16.
Comment #22
znerol commentedComment #24
znerol commentedPHPUnit tests are executed using the phpunit command line, hence TestRunnerKernel must not use NullSAPIAdapter.
Comment #26
znerol commentedMore Python than PHP work lately :)
Comment #27
mile23Needs a reroll.
+1 on the idea because separation of concerns is good. Some review stuff:
Drupal coding standards say we should CamelCase acronyms: https://www.drupal.org/node/608152#naming
We don't use @file tags just for Contains... any more.
Removing require_once for .inc files makes Mile23 happy. :-)
(Just to be clear: This isn't something you need to change.)
Comment #28
kostyashupenkoLooks like core/modules/simpletest/src/BrowserTestBase.php file is almost empty in 8.2.x for now. That's why this reroll is so massive
Comment #30
deepakaryan1988Comment #31
deepakaryan1988Rerolled the patch #28
Comment #33
deepakaryan1988Why is it not showing error? :(
Comment #34
deepakaryan1988Sorry forget to put newly created files in a last patch.
Comment #37
billywardrop commentedWe are working on this at DrupalCon Dublin
Comment #38
billywardrop commentedPatch attached
Comment #39
billywardrop commentedThis patch needs reviewed
Comment #40
billywardrop commentedComment #42
mile23There's no such thing as 'needs review' tag. Setting the status is fine.
Unfortunately there are quite a few failing tests still, so we're back to 'needs work.'
Comment #43
mile23I'm pretty sure this is a bad re-roll, since we did a bunch of work to inject $app_root.
Are you re-rolling from 8.3.x?
Comment #47
mile23Effort to isolate the test fixture part of bootEnvironment(): #2969741: Deprecate simpletest within DrupalKernel (DRUPAL_TEST_IN_CHILD_SITE)
Comment #56
bradjones1This could perhaps be achieved with the more modern
symfony/runtimecomponent. #3313404: Use symfony/runtime for less bespoke bootstrap/compatibility with varied runtime environmentsComment #59
andypostClosing to focus on common solution #3313404: Use symfony/runtime for less bespoke bootstrap/compatibility with varied runtime environments
Comment #60
kingdutchReopening this but postponing on #3313404: Use symfony/runtime for less bespoke bootstrap/compatibility with varied runtime environments so that that issue can remain small and focused on adding the runtime to Drupal but this issue moves over the actual environment set-up.
Comment #62
dwwComing here from #3453474: CLI entry point in Drupal Core. Ran head-first into this weirdness since the new CLI was trying to call
bootEnvironment()but that created a world of hurt for running commands inside tests sincebootEnvironment()does theset_error_handler()call yet tests don't want their own error handler to be forgotten. But sincebootEnvironment()happens only once ever (due to the static flag), it's hard/impossible for the new DrupalApplication entrypoint to responsibly restore the error handler after it completes. Ideally, we'd have a way to get most ofbootEnvironment()without messing with the error handler, so the CLI could get the goods without the headache of swapping error handlers. Or we move the error handler stuff to something that is tied to eachDrupalKernelso at least we can safely restore onceDrupalKernelis done. Or something. 😅Comment #63
mradcliffeRe-opening as #3313404: Use symfony/runtime for less bespoke bootstrap/compatibility with varied runtime environments was merged. Setting to Needs work.
Comment #64
andypostComment #65
dwwStarted some of the work from here at #3597692: [regression] The `dr` command doesn't set DRUPAL_TEST_IN_CHILD_SITE to deal with a test-only regression from the new
drCLI entry point.