When you install Drupal core on a project via composer, even if you specifically install composer dev dependencies, you will not get Drupal dev dependencies (including vfsstream), because require-dev is only read in the root composer.json. This non-recursive behavior is by design in composer.

This means that if you install Drupal core via composer, you cannot run any PHPUnit tests depending on vfsstream (of which there are many) either via the Simpletest UI or PHPUnit CLI. You have to know to manually install vfsstream in your own project's composer.json.

This is a bad and somewhat confusing DX. One simple solution would be to move vfsstream to Drupal's normal dependencies. I would argue that at least as long as the Simpletest module exists, it should be usable out of the box, meaning that vfsstream should be a fully-fledged Drupal dependency.

It looks like vfsstream was originally added as a full dependency, and only later moved to a dev dependency in #2444615: Move testing packages to require-dev in composer.json. But it also appears that no one in that issue considered the fact that dev dependencies aren't inherited via composer.

Comments

Dane Powell created an issue. See original summary.

Dane Powell’s picture

Issue summary: View changes
dawehner’s picture

This is totally just my own opinion here ...

I personally don't think this should be an issue. As far as I think you are not working on drupal core when working on a real life project, so it should not be up to you to run these tests :)

This means that if you install Drupal core via composer, you cannot run any PHPUnit tests depending on vfsstream (of which there are many) either via the Simpletest UI or PHPUnit CLI.

If you want to use vfsstream in your own tests I guess the right approach would be to add it to your own require-dev

If you want to work on drupal core, the installation via cloning the repo pulls the dependencies you need.

Dane Powell’s picture

I can see how this issue would go either way. But I believe that if Drupal provides a module that can be enabled via the UI (i.e. on a live install), that module should be expected to work out of the box.

Additionally, with composer-based workflows, it's a lot more convenient even for core developers to use tools like BLT and DrupalVM to install a site via Composer for development and testing purposes, rather than cloning from git and setting up a LAMP stack on your own. I guess what I'm really advocating for here is support for Composer-based development workflows.

Mile23’s picture

Title: PHPUnit tests fail due to missing vfsstream dependency on composer installs » Move composer dev requirements to drupal/drupal
Issue tags: +Composer, +Needs issue summary update

The only pieces of core that have a hard dependency on any dev requirements are: simpletest module and run-tests.sh. Simpletest is being deprecated: #2866082: [Plan] Roadmap for Simpletest

Let's assume that we're eventually going to get rid of wikimedia/composer-merge-plugin and drupal/drupal will directly require drupal/core.

In that scenario, we don't have a way to get phpunit or vfsstream for dev, because the merge plugin is doing that work for us.

So, if drupal/drupal is for core devs, then we should move the dev tools to it.

If we don't assume that we're going to get rid of the composer merge plugin, then the dev tools should remain where they are, because drupal/core is the one that needs them.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

bojanz’s picture

Version: 8.4.x-dev » 8.5.x-dev

I agree that dev tools should be moved to the root composer.json. That's the base of our project, not drupal/core.

Mile23’s picture

If we're promising that BTB will work for contrib (and is runnable through Simpletest UI), then we need, for instance, PHPUnit. So either PHPUnit as a dev requirement moves to drupal/drupal, or we keep the merge plugin and leave the dev requirements in drupal/core.

OR....

We have multiple composer.json files at the root level, such as dev.composer.json which requires the merge plugin and merges core. And then we have another composer.json file which does not, and requires drupal/core instead of merging it.

Using a file named dev.composer.json to build vendor/ leaves behind a lock file named dev.composer.lock, so that's handy.

So your instructions for running tests would look like this:

$ COMPOSER=dev.composer.json composer install
[ this reads dev.composer.lock and installs ]
$ php ./core/scripts/run-tests.sh --sqlite foo.sqlite --module my_contrib

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

greg.1.anderson’s picture

Status: Active » Closed (duplicate)

The Drupal dev dependencies were moved to the root composer.json file in #2912387: Stop using wikimedia/composer-merge-plugin.