ergebnis/rector-rules
Custom Rector rules from Ergebnis to standardize and modernize PHP code. Includes sorting associative arrays and match arms, converting Faker generator property fetches to method calls, and fixing namespaced symbol references. Install via Composer for dev.
PHPUnit Modernization Initiatives:
@test) to modern attributes (e.g., #test) to align with PHP 8.1+ standards and reduce technical debt.Code Quality & Maintainability Initiatives:
#[DataProvider], #[Before]) to improve test readability and maintainability.Use Cases:
Adopt When:
#test instead of @test).@dataProvider) exist in your codebase and need modernization.Look Elsewhere When:
*"This new Rector rule automates the migration from legacy PHPUnit annotations (e.g., @test) to modern attributes (e.g., #test), a critical step for teams upgrading to PHP 8.1+ or PHPUnit 9+. By integrating it into our CI/CD pipeline, we can:
@test and #test).*"This adds a new Rector rule to modernize PHPUnit tests:
PHPUnit\ReplaceTestAttributeWithTestPrefixRector: Converts legacy annotations (e.g., @test) to attributes (e.g., #test).// Before
class UserTest extends TestCase {
public function testLogin() { ... }
}
// After
class UserTest extends TestCase {
#[Test]
public function testLogin() { ... }
}
How it works:
composer require ergebnis/rector-rules --dev
rector.php:
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(
PHPUnit\ReplaceTestAttributeWithTestPrefixRector::class,
[]
);
};
rector process tests --dry-run
Why now?
*"Sick of manually updating PHPUnit tests from @test to #test? This package auto-fixes it for you. Key perks:
rector process tests
@dataProvider, @before, etc.--dry-run) previews changes.
Pro tip: Add it to your php-cs-fixer config or Git hooks to catch deprecated syntax early.
Try it:composer require ergebnis/rector-rules --dev
rector process tests --dry-run
```"
How can I help you explore Laravel packages today?