Problem/Motivation
We completed using Rector on core/tests code with withPreparedSets(typeDeclarations: true).
Now we can try running it on every test class in core, including modules, and cleanup the entire test codebase.
Proposed resolution
Use rector with type coverage on all tests classes in core; for now skip the TypedPropertyFromCreateMockAssignRector rule that we learned requires manual adjustments.
Install rector
$ composer require --dev rector/rector palantirnet/drupal-rector
Configure rector.php file
declare(strict_types=1);
use Rector\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector;
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)
->withSkip([
TypedPropertyFromCreateMockAssignRector::class,
])
->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
| Comment | File | Size | Author |
|---|
Issue fork drupal-3585505
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:
- 3585505-refactor-tests-code
changes, plain diff MR !15495
Comments
Comment #3
mondrakeComment #4
smustgrave commentedGoing to mark as nothing stands out as crazy. It does need a rebase though.
Comment #5
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. The merge request has merge conflicts and cannot be merged. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #6
mondrakerebased
Comment #7
alexpottComment #8
alexpottCommitted 95df9e9 and pushed to main. Thanks!
Comment #11
alexpottFYI we can run this again - there are couple of new things that got introduced but I think going forward is easier that re-rolling this all the time.
Comment #12
mondrakeFiled #3587327: Refactor tests code via Rector, May 2026 for #11.