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
Comment #2
Dane Powell CreditAttribution: Dane Powell at Acquia commentedComment #3
dawehnerThis 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 :)
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.
Comment #4
Dane Powell CreditAttribution: Dane Powell commentedI 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.
Comment #5
Mile23The 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.
Comment #7
bojanz CreditAttribution: bojanz at Centarro commentedI agree that dev tools should be moved to the root composer.json. That's the base of our project, not drupal/core.
Comment #8
Mile23If 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:
Comment #12
greg.1.anderson CreditAttribution: greg.1.anderson at Pantheon commentedThe Drupal dev dependencies were moved to the root composer.json file in #2912387: Stop using wikimedia/composer-merge-plugin.