When working on the revised version of our validation book, I needed to update our tests from PHPUnit 9 to PHPUnit 10.
This involved a handful of mechanical changes, like moving from annotations to attributes, or refactoring data providers to be static.
Rector helps automate this process with their PHPUnit 10 rule set.
But I didn't want to apply everything in this rule set, at least not all at once.
To keep the diffs more manageable to review, I wanted to run just 3 of the 16 rules in that set, and make a git commit for each one.
Thankfully, Rector makes this easy by letting you specify a single rule to run from the command line with the --only
option.
It looks like this:
vendor/bin/rector --only="\Rector\PHPUnit\SomeClassNameRector"
The syntax is straightforward, but two important things to note:
- The rule class must be fully qualified and surrounded by quotes.
- The rule has to be enabled in your
rector.php
configuration file, or it won't run. It can be part of a larger rule set, but it must be enabled.
I love how Rector not only helps me make large sweeping changes to my project, but also to do it in a controlled and precise way to match my desired workflow.
Here to help,
Joel
P.S. If you've never used Rector, but you'd like some help using it to standardize and modernize your project, get in touch.