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
<?php
declare(strict_types=1);
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadStmtRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
use Rector\TypeDeclaration\Rector\ClassMethod;
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/*',
RemoveUnusedConstructorParamRector::class => [
'core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php',
'core/tests/Drupal/TestTools/TestRunner/Configuration.php',
'core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayBaseTest.php',
],
RemoveDeadStmtRector::class => [
'core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php',
],
])
->withPreparedSets(
deadCode: true,
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
Then adjust manually any remaining error reported.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3620948
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
Comment #3
mondrakeComment #4
mondrake