1

I installed with Drupal with Composer (using drupal-scaffold) with Drupal files placed inside the web directory. When I run unit tests, two of them fail because Drupal expects to find the composer.json file inside the web directory whereas in my case composer.json is in the project root (which is obvious place for it).

Is this an issue with my configuration, or is it a problem with unit tests that make wrong assumptions?

The failing tests are Drupal\Tests\ComposerIntegrationTest::testComposerJson and Drupal\Tests\ComposerIntegrationTest::testComposerLockHash. Both fail with the following error message.

file_get_contents(web/composer.json): failed to open stream: No such file or directory

1
+50

Drupal with Composer uses the drupal-scaffold script which you mentioned. It seems that it does not include the composer.json and composer.lock files by default.

But the files are there: http://cgit.drupalcode.org/drupal/plain/

Looking at the plugin documentation on github in the Configuration section reveals that the composer.json and composer.lock files are not on the list to be included by default.

But the plugin is configurable, and you can actually specify the name of the files that should be additionally included.

So adding this in the extra section of your composer.json:

"drupal-scaffold" : {
    "includes" : [
        "composer.json",
        "composer.lock"
    ]
}

followed by running composer drupal-scaffold OR removing web/core directory and running composer install should get you the required files and make the tests pass.x

0

It looks like there's no way to override $this->root in /web/core/tests/Drupal/Tests/ComposerIntegrationTest.php (unless you add a patch to change the path to the main composer on line 45).

But you could use two symlinks so that /web/composer.json points to /composer.json and /web/composer.lock points to /composer.lock.

from /web directory:

ln -s ../composer.json composer.json
ln -s ../composer.lock composer.lock
4
  • Did you try it yourself? For me tests fail anyway complaining that file does not exists despite the symlink. Jun 22 '17 at 16:05
  • No, I didn't try it. Do you have symlinks enabled in your vhost? You could try Options +FollowSymLinks
    – oknate
    Jun 22 '17 at 17:15
  • OK, sorry, my bad. Link was pointing to wrong target and I didn't notice :) This workaround indeed works. But unfortunately it's just a workaround that will work only on *nix systems. Any idea why this test is even there? What's the purpose of testing composer files with drupal? Jun 23 '17 at 9:25
  • It tests if the composer.lock file (the version that is usually used to update a system running "composer install") is up-to-date with the composer.json file. I suppose because Drupal is encouraging managing site's dependencies with composer. If you don't want to run this test, you could remove the class on your system. If you're managing your site with composer, you could create a patch to remove the class file.
    – oknate
    Jun 23 '17 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.