Problem/Motivation

As we add more stuff into Drupal\TestTools namespace, more scripts that rely on classes under it need to add it to the classloader in their code.

Proposed resolution

Just add the namespace in the "autoloader-dev" section of the composer.json file, and let composer manage it for dev environments.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3614056

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review
mondrake’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Needs work

Makes sense could we add a CR for others to use? Imagine it'll be basic.

mondrake’s picture

Status: Needs work » Needs review

Not sure #5 really benefits anyone apart from a small group of people working on test tooling, but added a draft CR anyway.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Better safe then sorry suppose.

But LGTM thanks!

longwave’s picture

Status: Reviewed & tested by the community » Needs review

What about contrib or custom tests that use \Drupal\TestTools\Random?

KTB also refers to \Drupal\TestTools\Extension\SchemaInspector - will this break when used outside of core tests?

longwave’s picture

Actually why isn't it enough to add it to core/tests/bootstrap.php alone?

mondrake’s picture

#8 I do not think so - if you build a dev codebase with Composer both would still be accessible from the Composer autoloader no? This issue only really benefits additional scripts that will not rely on core/tests/bootstrap.php. For instance, run-tests.sh (that currently adds the namespace to the classloader); in the future #3523614: [CI] Collect and report deprecation statistics and details could need a cli script to consolidate/report deprecation statistics accessing classes i n this namespace, #3595595: Convert run-tests.sh to a set of dr commands may add to the dr script command defined in this namespace, etc etc

longwave’s picture

Maybe I'm missing something here but autoload-dev is marked root-only: https://getcomposer.org/doc/04-schema.md#autoload-dev

This means that it only takes effect for users working from a checkout of the Drupal core repo, and if it was in core/composer.json then it wouldn't work for those users either (because they aren't using it at the root level).

Where does Drupal\TestTools get added to the autoloader for users outside of the drupal/drupal development repo?

mstrelan’s picture

#11 I think it needs to go in autoload of drupal/core-dev

smustgrave’s picture

So what’s next steps for this one?

smustgrave’s picture

So is this a won't fix or different change needed? Should it be NW?

mstrelan’s picture

Status: Needs review » Needs work

I asked Claude about this. #11 is correct, so setting NW to figure this out. #12 won't work because drupal/core-dev is a metapackage and autoload doesn't apply there. We would need a real package (drupal/core-test-tools?), but not sure we really want to do that.