mrpunyapal / rector-pest
Rector upgrade rules for Pest - refactoring and best practices for Pest testing framework
Installs: 34
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 2
Forks: 2
Open Issues: 1
Type:rector-extension
pkg:composer/mrpunyapal/rector-pest
Requires
- php: ^8.2
- rector/rector: ^2.0
Requires (Dev)
- laravel/pint: ^1.18
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.0
- symplify/rule-doc-generator-contracts: ^11.2
This package is auto-updated.
Last update: 2025-12-10 15:56:25 UTC
README
Rector rules for PestPHP to improve code quality and help with version upgrades.
Available Rules
See all available Pest rules here.
Installation
composer require --dev mrpunyapal/rector-pest
Available Rule Sets
Code Quality
Improve your Pest tests with better readability and expressiveness.
// rector.php use MrPunyapal\RectorPest\Set\PestSetList; use Rector\Config\RectorConfig; return RectorConfig::configure() ->withPaths([ __DIR__ . '/tests', ]) ->withSets([ PestSetList::PEST_CODE_QUALITY, ]);
| Set | Description |
|---|---|
PestSetList::PEST_CODE_QUALITY |
Converts expect() assertions to use Pest's built-in matchers for better readability |
Version Upgrade Sets
Use PestLevelSetList to automatically upgrade to a specific Pest version. Sets for higher versions include sets for lower versions.
// rector.php use MrPunyapal\RectorPest\Set\PestLevelSetList; use Rector\Config\RectorConfig; return RectorConfig::configure() ->withPaths([ __DIR__ . '/tests', ]) ->withSets([ PestLevelSetList::UP_TO_PEST_40, ]);
| Set | Description |
|---|---|
PestLevelSetList::UP_TO_PEST_30 |
Upgrade from Pest v2 to v3 |
PestLevelSetList::UP_TO_PEST_40 |
Upgrade from Pest v2/v3 to v4 (includes v3 changes) |
Manual Version Configuration
Use PestSetList if you only want changes for a specific version:
// rector.php use MrPunyapal\RectorPest\Set\PestSetList; use Rector\Config\RectorConfig; return RectorConfig::configure() ->withPaths([ __DIR__ . '/tests', ]) ->withSets([ PestSetList::PEST_30, // Only v2→v3 changes ]);
| Set | Description |
|---|---|
PestSetList::PEST_30 |
Pest v2 → v3 migration rules |
PestSetList::PEST_40 |
Pest v3 → v4 migration rules |
Using Individual Rules
You can also use individual rules instead of sets:
// rector.php use MrPunyapal\RectorPest\Rules\ChainExpectCallsRector; use Rector\Config\RectorConfig; return RectorConfig::configure() ->withPaths([ __DIR__ . '/tests', ]) ->withRules([ ChainExpectCallsRector::class, ]);
Running Rector
# Preview changes vendor/bin/rector process --dry-run # Apply changes vendor/bin/rector process
Requirements
- PHP 8.2+
- Rector 2.0+
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
The MIT License (MIT). Please see License File for more information.