Problem/Motivation

Regular Rector run on every test class in core, including modules.

Proposed resolution

Use rector with type coverage on all tests classes in core.

Install rector

$ composer require --dev rector/rector palantirnet/drupal-rector

Configure rector.php file


declare(strict_types=1);

return Rector\Config\RectorConfig::configure()
  ->withBootstrapFiles([
     'vendor/palantirnet/drupal-rector/config/drupal-phpunit-bootstrap-file.php',
  ])
  ->withPaths([
    'core/tests',
    'core/modules/**/tests/src',
  ])
  ->withSkip([
    '*/*ixture*/*',
    '*/Annotation/Doctrine/*',
    'core/tests/Drupal/Tests/TestTools/ErrorHandler/DrupalDebugClassLoaderTest.php'
  ])
  ->withPreparedSets(typeDeclarations: true) 
  ->withImportNames(
    importDocBlockNames: false,
    importShortClasses: false,
    removeUnusedImports: false,
  );

Run rector
$ ./vendor/bin/rector

Fix code style
$ composer phpcbf

Update baseline
$ ./vendor/bin/phpstan analyse -c core/phpstan.neon.dist --generate-baseline=core/.phpstan-baseline.php --memory-limit=2G

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3587327

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

Title: Refactor tests code via Rector » Refactor tests code via Rector, May 2026

mondrake’s picture

Status: Active » Needs review
Issue tags: -no-needs-review-bot
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Nothing stood out that seemed to be an issue. LGTM.