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