Problem/Motivation
If you install Drupal via composer create-project, and run
../vendor/bin/phpunit --group OpenTelemetry (or any other test group), you get these errors:
1) Drupal\Tests\Composer\Generator\BuilderTest::testBuilder
The data provider specified for Drupal\Tests\Composer\Generator\BuilderTest::testBuilder is invalid
Class "Drupal\Composer\Composer" not found
/var/www/html/web/core/tests/Drupal/Tests/Composer/Generator/BuilderTest.php:91
2) Drupal\Tests\ComposerIntegrationTest::testComposerTilde
The data provider specified for Drupal\Tests\ComposerIntegrationTest::testComposerTilde is invalid
The "/var/www/html/web/composer" directory does not exist.
/var/www/html/web/core/tests/Drupal/Tests/ComposerIntegrationTest.php:55
3) Drupal\BuildTests\Composer\ComposerValidateTest::testValidateComposer
The data provider specified for Drupal\BuildTests\Composer\ComposerValidateTest::testValidateComposer is invalid
The "/var/www/html/web/composer" directory does not exist.
/var/www/html/web/core/tests/Drupal/BuildTests/Composer/ComposerValidateTest.php:29
--
There were 2 PHPUnit test runner warnings:
1) No tests found in class "Drupal\Tests\Composer\Generator\BuilderTest".
2) No tests found in class "Drupal\BuildTests\Composer\ComposerValidateTest".
This is because there's no composer in that location when you use composer create project.
While we don't have to support all tests passing when using composer create-project, it's reasonable to want to run one or two tests or use @group.
I don't think we can make this test find the composer directory, but we could possibly try to skip the test if it can't find the composer directory in the first place. Not sure how that works with phpunit test discovery.
Comments
Comment #3
catchCrediting @slashrsm who found the bug.
Comment #4
catchComment #5
guignonvMaybe you could try a different command line from parent directory:
./vendor/bin/phpunit -c ./core ./modules/contrib/or something like that, adapted to your directory structure.
I had the same errors (Composer not found) and what worked for me was
./vendor/bin/phpunit -c ./web/core ./web/modules/contrib/. I also added vendor/bin to my PATH but not sure it helped.If it works that way then, maybe the online documentation should be updated accordingly...
Comment #6
smulvih2I'm running into the same issue with this:
There were 2 PHPUnit errors:
The first error is looking for class
Drupal\Composer\Composer, which would suggest composer is in thevendor/drupal/composerdirectory, but it's location in my project is actuallyvendor/composer/composer.Comment #7
smulvih2Ok think I found the issue. For some reason, composer is not bringing in the /composer directory from core, still troubleshooting why.
Comment #8
smulvih2Ok figured out the issue with my tests, a bit confusing.
I thought this was
drupal/core: https://git.drupalcode.org/project/drupal/-/tree/11.1.x?ref_type=headsBut the composer.json in the root of this repo is
drupal/drupal. There is another composer.json file in /core, and that'sdrupal/core. So when we are requiring drupal/core-recommended, that requires drupal/core, and so the other files/directories in the root of that repo are not included.To fix the issue, I added
drupal/drupalto require-dev. This puts drupal/drupal in the vendor directory. I then use a composer post install/update script to move vendor/drupal/drupal/composer/* into html/composer (only if it exists with require-dev).Now the
Drupal\Tests\Composer\Generator\BuilderTestclass, which requires the /composer directory to be in place, can access the proper drupal verison of composer with theComposer::drupalVersionBranch()method, which is obviously drupal specific.