Skip to content

[CodeQuality] Rule to enforce test method code style#668

Merged
TomasVotruba merged 3 commits into
rectorphp:mainfrom
Xammie:add-test-case-style-rules
Jun 26, 2026
Merged

[CodeQuality] Rule to enforce test method code style#668
TomasVotruba merged 3 commits into
rectorphp:mainfrom
Xammie:add-test-case-style-rules

Conversation

@Xammie

@Xammie Xammie commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

This adds two rules to convert the name of test methods to either CamelCase or snake_case.

// When using
use Rector\PHPUnit\CodeQuality\Rector\ClassMethod\PreferTestsWithSnakeCaseRector
$rectorConfig->rule(PreferTestsWithSnakeCaseRector::class);

// From
public function testItWillCreateNewProduct() {}
// To
public function test_it_will_create_new_product() {}

@Xammie Xammie changed the title [CodeQuality] Rule to enfore test method style [CodeQuality] Rule to enfore test method code style Apr 3, 2026
@Xammie Xammie changed the title [CodeQuality] Rule to enfore test method code style [CodeQuality] Rule to enforce test method code style Apr 3, 2026
@Xammie

Xammie commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

@TomasVotruba this is ready to review :)

Comment thread rules/CodeQuality/Rector/Class_/PreferTestsWithCamelCaseRector.php
@samsonasik

Copy link
Copy Markdown
Member

for additional note: I think this should be your own custom rule for your specific use case :)

@Xammie

Xammie commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

@samsonasik thank you for the review.

Regarding your additional note, do you mean this should not be part of rector php and instead be part of a separate package?

@samsonasik

samsonasik commented Apr 30, 2026

Copy link
Copy Markdown
Member

yeah, imo, this should be not part of rector repo, you can create your own custom rector rule for it as this is by preference

@Xammie

Xammie commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

The reason I thought it would fit well here is because this is similar to PreferPHPUnitSelfCallRector and PreferPHPUnitThisCallRector in a way, because that is mostly a preference in code style.

Ofcourse if you still don't think this should be part of rector-phpunit then I completely understand and I will put it into a new package.

@TomasVotruba

TomasVotruba commented Jun 26, 2026

Copy link
Copy Markdown
Member

I'm looking into this. Seems valid to have the direction as well 👍

@TomasVotruba TomasVotruba force-pushed the add-test-case-style-rules branch from 40f12c6 to 2fdf38b Compare June 26, 2026 09:39
@TomasVotruba

Copy link
Copy Markdown
Member

Ready to ship 👍 Thank you!

@TomasVotruba TomasVotruba merged commit ee4dc09 into rectorphp:main Jun 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants