PHPackages                             mrpunyapal/rector-pest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. mrpunyapal/rector-pest

ActiveRector-extension[Testing &amp; Quality](/categories/testing)

mrpunyapal/rector-pest
======================

Rector upgrade rules for Pest - refactoring and best practices for Pest testing framework

0.2.3(2mo ago)4717.6k—5.6%413MITPHPPHP ^8.2CI passing

Since Dec 3Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/MrPunyapal/rector-pest)[ Packagist](https://packagist.org/packages/mrpunyapal/rector-pest)[ GitHub Sponsors](https://github.com/mrpunyapal)[ RSS](/packages/mrpunyapal-rector-pest/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (22)Used By (13)

Rector Pest
===========

[](#rector-pest)

[![Latest Version on Packagist](https://camo.githubusercontent.com/31bc6952e11217269533c59f73b916e647db603dd6506de94c6246f71bde2b3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d7270756e796170616c2f726563746f722d706573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mrpunyapal/rector-pest)[![Total Downloads on Packagist](https://camo.githubusercontent.com/a7a893ab63c76181d32ac18366f59bc23c4f733669ad53a4d2a98581b6b3937a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d7270756e796170616c2f726563746f722d706573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mrpunyapal/rector-pest)[![CI](https://github.com/mrpunyapal/rector-pest/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mrpunyapal/rector-pest/actions/workflows/ci.yml)

Rector rules for [PestPHP](https://pestphp.com/) to improve code quality and help with version upgrades.

Available Rules
---------------

[](#available-rules)

See all available Pest rules [here](/docs/rules.md).

Installation
------------

[](#installation)

```
composer require --dev mrpunyapal/rector-pest
```

Available Rule Sets
-------------------

[](#available-rule-sets)

### Code Quality

[](#code-quality)

Improve your Pest tests with better readability and expressiveness.

```
// rector.php
use RectorPest\Set\PestSetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/tests',
    ])
    ->withSets([
        PestSetList::PEST_CODE_QUALITY,
    ]);
```

SetDescription[`PestSetList::PEST_CODE_QUALITY`](config/sets/pest-code-quality.php)Converts expect() assertions to use Pest's built-in matchers for better readability[`PestSetList::PEST_CHAIN`](config/sets/pest-chain.php)Merges multiple expect() calls into chained expectations and optimizes their order.### Version Upgrade Sets

[](#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 RectorPest\Set\PestLevelSetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/tests',
    ])
    ->withSets([
        PestLevelSetList::UP_TO_PEST_40,
    ]);
```

SetDescription`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

[](#manual-version-configuration)

Use `PestSetList` if you only want changes for a specific version:

```
// rector.php
use RectorPest\Set\PestSetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/tests',
    ])
    ->withSets([
        PestSetList::PEST_30, // Only v2→v3 changes
    ]);
```

SetDescription[`PestSetList::PEST_30`](config/sets/pest30.php)Pest v2 → v3 migration rules[`PestSetList::PEST_40`](config/sets/pest40.php)Pest v3 → v4 migration rulesChaining Expectations
---------------------

[](#chaining-expectations)

The `PEST_CHAIN` set automatically merges multiple `expect()` calls into a single chained expression.

```
// rector.php
use RectorPest\Set\PestSetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/tests',
    ])
    ->withSets([
        PestSetList::PEST_CODE_QUALITY,
        PestSetList::PEST_CHAIN,
    ]);
```

**Before:**

```
expect($value1)->toBe(10);
expect($value2)->toBe(20);
expect($value3)->toBe(30);
```

**After:**

```
expect($value1)->toBe(10)->and($value2)->toBe(20)->and($value3)->toBe(30);
```

> **Note on formatting:** Chained output is currently printed inline. Per-node newline control (to produce one method per line) requires an upstream change to `rector/rector`'s printer. See [rectorphp/rector-src#7910](https://github.com/rectorphp/rector-src/pull/7910) for the planned upstream contribution.

Using Individual Rules
----------------------

[](#using-individual-rules)

You can also use individual rules instead of sets:

```
// rector.php
use RectorPest\Rules\ChainExpectCallsRector;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/tests',
    ])
    ->withRules([
        ChainExpectCallsRector::class,
    ]);
```

Running Rector
--------------

[](#running-rector)

```
# Preview changes
vendor/bin/rector process --dry-run

# Apply changes
vendor/bin/rector process
```

Requirements
------------

[](#requirements)

- PHP 8.2+
- Rector 2.0+

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance87

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

20

Last Release

80d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/230c58a4f918ca3e3f2988b38721230698bce88f76ae9087e4377ba0b3a074d5?d=identicon)[MrPunyapal](/maintainers/MrPunyapal)

---

Top Contributors

[![MrPunyapal](https://avatars.githubusercontent.com/u/53343069?v=4)](https://github.com/MrPunyapal "MrPunyapal (298 commits)")[![faissaloux](https://avatars.githubusercontent.com/u/60013703?v=4)](https://github.com/faissaloux "faissaloux (1 commits)")[![guanguans](https://avatars.githubusercontent.com/u/22309277?v=4)](https://github.com/guanguans "guanguans (1 commits)")[![raphaelstolt](https://avatars.githubusercontent.com/u/48225?v=4)](https://github.com/raphaelstolt "raphaelstolt (1 commits)")

---

Tags

testingphpunitpestdevstatic analysisrefactoringastrectorpestphpinstant-upgrades

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mrpunyapal-rector-pest/health.svg)

```
[![Health](https://phpackages.com/badges/mrpunyapal-rector-pest/health.svg)](https://phpackages.com/packages/mrpunyapal-rector-pest)
```

###  Alternatives

[donatj/mock-webserver

Simple mock web server for unit testing

1382.5M80](/packages/donatj-mock-webserver)[savinmikhail/add_named_arguments_rector

Rector rule to add names to arguments for functions'/methods' calls

1969.5k3](/packages/savinmikhail-add-named-arguments-rector)[guanguans/laravel-soar

SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

2227.8k](/packages/guanguans-laravel-soar)[code-distortion/adapt

A Laravel package that builds databases for your tests, improving their speed.

2835.5k](/packages/code-distortion-adapt)[mrpunyapal/peststan

PHPStan extension for Pest PHP testing framework

291.5k4](/packages/mrpunyapal-peststan)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
