Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
#2252991: phpUnit tests for ModuleHandler adds DRUPAL_ROOT to the phpUnit bootstrap since it is so heavily used in our code base. As follow up, remove its use from other unit tests.
Comment | File | Size | Author |
---|---|---|---|
#12 | test.unit_.drupal_root.12.patch | 3.42 KB | sun |
#8 | drupal_root-2270323-8.patch | 46.36 KB | dawehner |
#5 | remove-drupal-root-definitions-2270323-5.patch | 3.45 KB | neclimdul |
Comments
Comment #1
jhedstromThis no longer completely applies.
Comment #2
sunDRUPAL_ROOT should not have been added to the PHPUnit bootstrap.php.
I don't understand why it was added, and even added to a section that clearly states that constants should be removed...?
The globally defined constants are tampering the environment of all tests, which is bad.
Comment #3
neclimdulI agree, you should be concerned. But we already do that because we don't force phpUnit tests to run tests in process isolation, we just do it in the tests files. Technically that's worse because it means we can accidentally rely on run order for tests to work. This just puts it up front and consistent.
Comment #4
alansaviolobo CreditAttribution: alansaviolobo commentedComment #5
neclimdulComment #6
dawehnerDo we have a @TODO/issue to remove this globalness, for example in the phpunit bootstrap?
I guess this could be moved to \Drupal without any problems? Not sure about early installer though, tbh.
Comment #7
sunDue to recent work on PHPUnit, I now agree with this change/cleanup. I don't see a way around avoiding
DRUPAL_ROOT
in the phpunit bootstrap.php either.In fact, meanwhile I believe that an
APP_ROOT
constant like this should actually be supplied universally, centrally, and standardized by Composer's autoloader (which deals with many similar band-aid material like PHP INI settings anyway already). The constant is not really Drupal-specific; it simply points to the base/root directory of the application. I'll try to create an issue for that.That said, note that there are some unit tests in HEAD that try to avoid
DRUPAL_ROOT
and thus use excessive relative directory name traversals à ladirname(dirname(dirname(__DIR__)))
or__DIR__ . '/../../../../'
to locate test fixtures. Would be great to adjust those accordingly here?Comment #8
dawehnerInstead of using DRUPAL_ROOT we should now use $container->getParameter('app.root'), so we no longer need this workaround.
This is really just a start for now.
Comment #9
sun@dawehner: Please note the issue title - this issue is about phpunit tests only. There is no container in unit tests.
Can you create a separate issue for #8? (the proposal is questionable, but not to be discussed here)
Comment #11
dawehnerOkay.
Comment #12
sunRe-rolled against HEAD. No change, so RTBC.
Comment #13
sunCorrecting slightly misleading issue title.
Comment #14
webchickCommitted and pushed to 8.x. Thanks!