Installation Add the package via Composer:
composer require --dev testo/bridge-rector
Ensure rector.php exists in your project root (create if missing) and include the package rules:
return [
'rules' => [
\Testo\BridgeRector\Set\TestSuiteBridgeSet::class,
],
];
First Use Case Run Rector to convert a single test file (e.g., PEST → PHPUnit):
vendor/bin/rector process tests/ExampleTest.php --dry-run
Verify the output matches your target framework’s syntax.
Where to Look First
test() → public function test_()).tests directory for real-world examples.Incremental Migration
--paths:
vendor/bin/rector process tests/Unit --dry-run
--exclude to skip legacy tests until ready:
vendor/bin/rector process tests/ --exclude="Legacy/*"
CI/CD Integration
- name: Migrate tests
run: vendor/bin/rector process tests/ --dry-run
Custom Rule Extensions
TestSuiteBridgeSet by creating a custom rule set:
// rector.php
return [
'sets' => [
TestSuiteBridgeSet::class,
\App\CustomTestRectorSet::class, // Your custom rules
],
];
rector to auto-fix tests before commits (via tools like Husky).vendor/bin/rector process tests/Unit/ tests/Feature/ --parallel
False Positives in Dry Runs
test() used in non-test contexts). Use --exclude-paths to ignore specific files/directories.Stateful Transformations
beforeEach to setUp) rely on file structure. Run Rector on the entire test suite first, not individual files.--paths="tests/" to process all tests at once.Dependency Conflicts
PHPUnit or PEST sets). Explicitly order sets in rector.php:
return [
'sets' => [
\Rector\PHPUnit\Set\PHPUnitSet::class, // Base rules first
TestSuiteBridgeSet::class, // Override last
],
];
Unsupported Features
expect() vs. PHPUnit’s assertEquals()). Review the rule list for gaps.--verbose to see which rules are applied:
vendor/bin/rector process tests/ --verbose
--rule=TestSuiteBridgeSet\ConvertTestFunctionRule.git diff to spot unexpected changes:
vendor/bin/rector process tests/ --dry-run | git apply --check
Custom Rules
AbstractTestSuiteBridgeRule to handle framework-specific quirks:
use Testo\BridgeRector\Rule\AbstractTestSuiteBridgeRule;
final class CustomPestToPHPUnitRule extends AbstractTestSuiteBridgeRule {
public function getRuleDefinition(): NodeTypeResolution {
return new NodeTypeResolution(
PestTestCase::class,
fn(PestTestCase $node) => $this->transform($node)
);
}
}
Configuration Overrides
rector.php:
return [
'rules' => [
TestSuiteBridgeSet::class => [
\Testo\BridgeRector\Rule\ConvertTestFunctionRule::class => false,
],
],
];
Post-Processing
php-cs-fixer) to normalize code after conversion:
vendor/bin/rector process tests/ && vendor/bin/php-cs-fixer fix tests/
How can I help you explore Laravel packages today?