Comments (6)
Urgh, that's because Drupal's core/tests/bootstrap.php does this:
$loader = require __DIR__ . '/../../autoload.php';
and so is loading repos/drupal/autoload.php
. That works because of the workaround in this project template which symlinks the vendor/ folder. But elsewhere in core/tests/bootstrap.php, in drupal_phpunit_contrib_extension_directory_roots() it registers namespaces from contrib modules with the autoloader, and obviously, doesn't find any contrib modules because they're not in /repos/drupal.
Not sure how to tackle this. We're including core/tests/bootstrap.php from phpunit.xml, which is handwritten and so knows the path to the file. But once inside that file, it can't know that it's symlinked in.
from drupal-core-development-project.
I think this can only be fixed in core as part of https://www.drupal.org/project/drupal/issues/1792310.
As a workaround, you could hack the file to change all instances of DIR to the path with the symlink, that is, web/core/tests rather than repos/drupal/core/tests.
from drupal-core-development-project.
I can see how we could do this before that core issue is fixed, but it's fiddly.
Method 1 - quick but dirty, doable by users:
- Copy the version of core/tests/bootstrap.php
from the MR for the core issue -- https://git.drupalcode.org/project/drupal/-/blob/2fb261b10d31a23eccfd52d68fbd61e34e999d92/core/tests/bootstrap.php -- and place it somewhere like the project root - Make a second phpunit.xml file in the project root, called, say, phpunit-contrib.xml
- Edit that file to define the location variables PROJECT_ROOT and DRUPAL_APP_ROOT, as demonstrated in the MR: https://git.drupalcode.org/project/drupal/-/blob/2fb261b10d31a23eccfd52d68fbd61e34e999d92/core/phpunit.xml.dist
- Edit that file so that its bootstrap is the bootstrap.php file you've just made
- To run contrib tests, use the
-c
flag to load the phpunit-contrib.xml file
Method 2 - longer and also dirty, fixed in this template:
- We add a patch for core/tests/bootstrap.php from that MR into this template
- Add a step to the installation process for this template which:
a. copies core/tests/bootstrap.php to the project root
b. applies the patch to it - Add details to the README for adding the location environment variables to phpunit.xml
from drupal-core-development-project.
I'm experimenting with this, and WEIRD STUFF is happening.
I put a phpunit-contrib.xml file in the project root, pointing to a custom test bootstrap.php file at tests/bootstrap.php.
A contrib kernel test fails with:
PHPUnit\Framework\Exception: Fatal error: Uncaught PHPUnit\Util\Xml\Exception: Could not read "phpunit-contrib.xml". in /Users/joachim/Sites/drupal-core-composer/vendor/phpunit/phpunit/src/Util/Xml/Loader.php:41
This appears to be because at some point the working dir is changed to 'web'. I assume it's this in KernelTestBase:
// Change the current dir to DRUPAL_ROOT.
chdir(static::getDrupalRoot());
So, rather than go digging into why that is done, I symlinked phpunit-contrib.xml into 'web'.
The test then fails with:
PHPUnit\Framework\Exception: Warning: require_once(./tests/bootstrap.php): Failed to open stream: No such file or directory in Standard input code on line 119
Presumably that is the dir change causing that again.
I then replaced the bootstrap file location in phpunit-contrib.xml with an absolute path.
(Though what confuses me is how this all works when phpunit is run without the -c option and it just finds the phpunit.xml file in the current working directory. What happens after KernelTestBase does a chdir() -- how does PHPUnit find that file afterwards?)
I got this:
PHPUnit\Framework\Exception: Warning: Class "\Drupal\Tests\DocumentElement" not found in /Users/joachim/Sites/drupal-core-composer/tests/bootstrap.php on line 172
Which I've seen before in other circumstances -- it's the autoloader not being set up with the correct path. So again, it's to do with being in the Drupal root.
from drupal-core-development-project.
(Though what confuses me is how this all works when phpunit is run without the -c option and it just finds the phpunit.xml file in the current working directory. What happens after KernelTestBase does a chdir() -- how does PHPUnit find that file afterwards?)
In that circumstance, PHPUnit\Util\Xml\Loader::loadFile() gets an absolute path. With the -c option it gets a relative path.
from drupal-core-development-project.
Related Issues (9)
- Error messages when running composer install, after switching from Drupal core 9.2.x to 9.1.x HOT 10
- ComposerProjectTemplatesTest.php doesn't work HOT 7
- Project does not work with core's 10.0.x branch HOT 2
- [drush] Uncaught Exception: Could not locate autoload.php when `vendor/` folder is symlinked HOT 5
- Update dependencies for Drupal 10 HOT 3
- Dependency conflicts of Drupal core 8.9.x and var-dumper:^5.1 HOT 3
- Add ability to easily check Drupal coding standards HOT 1
- DRUPAL_ROOT value is the symlinked directory, instead of the project location HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drupal-core-development-project.