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

Issue fork drupal-3585505

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
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +no-needs-review-bot

Going to mark as nothing stands out as crazy. It does need a rebase though.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new98 bytes

The 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.

mondrake’s picture

Status: Needs work » Reviewed & tested by the community

rebased

alexpott’s picture

Issue summary: View changes
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 95df9e9 and pushed to main. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed 95df9e91 on main
    task: #3585505 Refactor tests code via Rector
    
    By: mondrake
    
alexpott’s picture

FYI 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.

mondrake’s picture