Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299133

[May 2024] Add void return typehints to all test methods

$
0
0

Problem/Motivation

Follow-up to #3353210-37: [PHPUnit 10] @dataProvider methods must be declared static and public.

Test methods should have an appropriate typehint: void in most cases or something else if a @depends annotation is specified on dependent tests (do we have that case at all?)

Steps to reproduce

Proposed resolution

Fix with rector.

composer require --dev rector/rector

Patch the rector rule to apply only to test* methods, add this snippet to \Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector::shouldSkipClassMethod.

if (!\str_starts_with($classMethod->name->name, 'test')) {
    return \true;
}

rector.php

<?php

return Rector\Config\RectorConfig::configure()
  ->withRules([
    Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector::class,
  ])
  ->withPaths([
    'core/tests',
    'core/tests/*/*',
    'core/*/*/tests',
  ])
  ->withSkipPath(
    'core/tests/Drupal/Tests/Component/Annotation/Doctrine',
  );

Run rector

./vendor/bin/rector

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 299133

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>