Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Rector Pest

Rector Pest Laravel Package

mrpunyapal/rector-pest

Rector rules for PestPHP that improve test code quality and ease version upgrades, plus a semantic remediation layer with canonical issue IDs and diagnostic-to-fix mapping for safe Pest-specific fixes.

View on GitHub
Deep Wiki
Context7

Rector Pest provides a set of Rector rules for PestPHP that improve test code quality and streamline version upgrades. It also includes a semantic remediation layer for safe Pest-specific diagnostics, keeping canonical issue identifiers and diagnostic-to-fix mappings inside the package—so rules stay analyzer-agnostic and ready for future PestStan interoperability.

  • Code-quality rule set for more readable, expressive Pest tests
  • Fixes PestStan-aligned anti-patterns like invalid beforeAll()/afterAll() in describe() blocks and static callbacks needing instance binding
  • Auto-fixes invalid literal repeat() counts and redundant literal type expectations
  • Safe-by-design: ambiguous or semantics-changing fixes are modeled but not applied
  • No runtime PestStan dependency for consumers
Frequently asked questions about Rector Pest
What is mrpunyapal/rector-pest used for?
It is a dev-only Composer package that ships Rector rules for PestPHP tests. The rules automate test-code improvements such as converting PHPUnit assertions to expect() syntax, tightening chained expectations, and applying Pest version upgrades. You wire the sets into your rector.php and run Rector over your tests directory at build time; nothing ships to production.
How do I install mrpunyapal/rector-pest in a Laravel project?
Run composer require --dev mrpunyapal/rector-pest with an exact version pin in your require-dev block. Then import PestSetList or PestLevelSetList into your existing rector.php, point withPaths() at your tests directory, and run vendor/bin/rector process --dry-run first. The package registers itself as a Rector extension, so no service provider or config publishing is required.
Which PHP, Rector, and Pest versions does rector-pest require?
The package requires PHP 8.2 or newer and Rector 2.0 or newer, with Rector 2.4.1+ needed for multi-line chained-expectation formatting. The versioned level sets target Pest 3 and Pest 4, so Pest 2-era projects get little value from the upgrade chains. Optional rule groups add their own requirements, such as illuminate/support for the Laravel set and pestphp/pest-plugin-browser for the Browser set.
What is the difference between PestSetList and PestLevelSetList?
PestSetList groups behavior-oriented rules that improve readability and expressiveness in existing tests, such as expectation chaining and assertion conversion. PestLevelSetList groups versioned upgrade chains that move test code forward as you bump Pest majors. Use the quality set for day-to-day cleanup and the level sets only when you are actually planning a Pest upgrade.
Does rector-pest add a runtime dependency to my Laravel application?
No. It is a build-time, dev-only dependency that transforms source files on disk; there is no runtime service provider, facade, or application coupling. Once the rewrite is committed you can keep the package in require-dev or remove it entirely and the tests still run. That makes its blast radius limited to your test suite and CI pipeline.
How do I use rector-pest to upgrade Pest test code between major versions?
Enable the appropriate PestLevelSetList chain in rector.php that matches your target Pest version, then run Rector on a short-lived branch. Run the full test suite before and after the transformation to confirm behavior is unchanged. The PEST_MIGRATION set is intentionally opt-in because it can shift assertion and exception semantics, so review those diffs manually rather than auto-merging.
How do I preview and review the changes before applying them?
Always start with vendor/bin/rector process --dry-run to print the proposed diffs without writing files. Inspect the output for changes to failure granularity, such as expect() calls collapsed into and() chains, and for converted exception assertions. Commit on a dedicated branch and require a green CI run so reviewers can compare test behavior before and after.
Can rector-pest convert PHPUnit assertions to Pest expect() syntax?
Yes. Rules such as ConvertAssertToExpectRector and ConvertExpectExceptionToThrowRector rewrite PHPUnit-style assertions and exception expectations into Pest idioms. Because these change how failures are reported and how exceptions are thrown, the maintainer treats them as semantic changes rather than formatting. Review those diffs on a representative sample of tests before rolling out broadly.
Is mrpunyapal/rector-pest still maintained, and what are the alternatives?
The GitHub repository is archived, so there will be no upstream fixes, no Pest v5 or Rector 3 alignment, and no security triage, although existing Packagist versions still install. The official alternative is pestphp/pest-plugin-rector, which the README itself points to. Treat the archived package as a tactical accelerator or a fork candidate, and check it against any internal abandoned-dependency policy before adoption.
Does rector-pest support Laravel browser tests and Dusk-style assertions?
There is a Browser rule set that rewrites verbose expect($page->getter())->toBe(...) patterns into dedicated Pest browser plugin assertions with clearer failure messages. It requires pestphp/pest-plugin-browser to be installed, and there is a separate set for Laravel-specific rules that needs illuminate/support. This Browser set is often the most concrete readability and debugging win for end-to-end suites.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections