pestphp/pest
Pest is an elegant PHP testing framework focused on simplicity and developer joy. Write expressive, modern tests with a clean syntax, powerful expectations, and a great DX for PHP projects—built for fast feedback and readable suites.
Http, Database, Mockery). The laravel preset includes Laravel-specific assertions (e.g., toHaveValidationError(), toExtend()), reducing boilerplate and aligning with Laravel’s testing conventions.toUseTrait(), toExtend(), and toHaveSuspiciousCharacters() assertions enable static analysis of code structure, which is critical for enforcing clean architecture in Laravel monoliths or modular apps. This aligns with tech debt reduction initiatives.pest command auto-detects test files and runs them in parallel by default, making it drop-in replaceable.actingAs(), followRedirects()), so no changes are needed for existing test logic. The laravel preset even auto-loads Laravel’s testing helpers.parallel keyword, GitHub Actions’ matrix strategy). Risk mitigation:
--parallel before pushing to CI.--shard for large suites to avoid CI timeouts.--shard) be integrated into CI pipelines?toUseTrait(), toExtend()) be enforced in PR checks?pest-plugin-browser) be centralized or allowed per-team?dd, dump()) be standardized across parallel tests?actingAs(), actingAsUser()).assertEquals(), expectException()) work unchanged. This ensures no regression in test coverage.@test, @group).| Phase | Action | Tools/Commands | Risk Mitigation |
|---|---|---|---|
| 1. Evaluation | Run existing tests with Pest in parallel mode to benchmark speed. | ./vendor/bin/pest --parallel |
Compare CI runtime vs. PHPUnit. |
| 2. Pilot | Rewrite 1–2 test suites in Pest (e.g., a high-churn feature). | composer require pestphp/pest --dev + php artisan pest:install |
Use feature flags to isolate changes. |
| 3. Gradual Rollout | New tests must use Pest; legacy PHPUnit tests deprecated but still run. | pest --testdox for documentation. |
Set a deprecation timeline (e.g., 12 months). |
| 4. Full Migration | Convert remaining PHPUnit tests to Pest. | php artisan pest:convert (if available). |
Automated refactoring for simple tests. |
| 5. Optimization | Enable parallel sharding, browser tests, and architecture rules. | --update-shards, --browser. |
Monitor CI stability. |
create(), assertDatabaseHas(), etc.--with syntax replaces PHPUnit’s dataProvider, but legacy providers can coexist.toHaveValidPayment()).--junit for test reporting).it() vs. public function test()).// PHPUnit
public function test_user_can_login() { ... }
// Pest
it('logs in a user', function () { ... });
it('returns a 404 for invalid routes')->get('/invalid')->assertStatus(404);
--parallel in CI to reduce runtime by 50–70%.- run: ./vendor/bin/pest --parallel --shard=${{ matrix.shard }}/4
it('loads the dashboard', function () {
$this->browser()->visit('/dashboard')
->assertSee('Welcome');
});
toUseTrait(), toExtend() in CI checks to prevent tech debt.it('does not use deprecated controllers')->expect('App\Http\Controllers\OldController')->not->toBeUsed();
How can I help you explore Laravel packages today?