pestphp/pest-plugin-drift
Pest Plugin Drift adds drift detection to your Pest test suite, helping catch behavioral changes and flaky differences across runs. Install alongside Pest to track and report unexpected output or snapshot mismatches during testing.
Testing Paradigm Alignment:
The pestphp/pest-plugin-drift package (v0.2.0) introduces depends annotation conversion, a targeted feature for teams migrating from PHPUnit to Pest. This aligns with Laravel’s evolving testing ecosystem by:
@depends conversion bridges a critical gap for teams with legacy PHPUnit test suites, particularly those relying on test dependencies (e.g., multi-step workflows, setup/teardown patterns).@depends is translated to Pest’s uses() or beforeEach(), but complex dependencies (e.g., data providers) may still require manual refactoring.Laravel Ecosystem Synergy: Unchanged. The plugin remains tightly integrated with:
get(), post() assertions).uses() or beforeEach()).Testing facade (e.g., actingAs(), withoutMiddleware()) should verify compatibility with Pest’s uses() syntax for test dependencies.Isolation vs. Coupling:
depends conversion localizes migration effort to test dependencies, leaving other assertions intact.@depends tests may cause silent failures if not validated during migration.Low-Coding Barrier:
The depends conversion requires minimal setup but introduces a new dependency:
// pest.php
return [
'plugins' => [
PestPluginDrift::make()->assertSnapshotMatches(),
PestPluginConverter::make()->convertDependsAnnotations(), // New
],
];
uses()/beforeEach() support).mandisma/pest-converter (v0.2.0+) for annotation parsing.@depends translation but skips unsupported annotations (e.g., @dataProvider).Snapshot Storage: Unchanged. Storage backends (filesystem, database, S3) remain configurable, but large-scale teams should evaluate:
--parallel) may increase snapshot I/O contention.CI/CD Readiness:
@depends conversion before running drift tests:
# GitHub Actions example
- name: Convert PHPUnit @depends to Pest
run: vendor/bin/pest-converter migrate
- name: Run Drift Tests
run: pest --minimal
@dataProvider or custom PHPUnit traits will fail silently unless pre-validated.pest --update-snapshots) to avoid accidental merges.| Risk Area | Mitigation Strategy | Update for v0.2.0 |
|---|---|---|
| Snapshot Bloat | Use .pestignore and prune old snapshots. |
No change. |
| False Positives | Combine with explicit assertions (expect()->toBe()). |
No change. |
| Performance Overhead | Exclude heavy tests; use --parallel for Pest. |
New: Monitor snapshot I/O during parallel test execution. Consider distributed storage (e.g., Redis) for large teams. |
| Migration from PHPUnit | Validate @depends tests pre-migration; use pest-converter for automation. |
Updated: The depends conversion reduces risk but introduces new risks: |
- Circular Dependencies: Add a pre-migration lint step to detect cycles (e.g., pest-converter validate). |
||
- Unsupported Annotations: Document blockers (e.g., @dataProvider) in migration docs. |
||
| Storage Backend Risks | Default to filesystem; evaluate S3 for scalability. | New: For multi-region teams, consider multi-AZ snapshot storage (e.g., S3 Cross-Region Replication) to avoid drift test failures during outages. |
| Test Flakiness | Isolate drift tests in CI; use --update-snapshots cautiously. |
New: Flaky Dependencies: Tests with @depends converted to uses() may fail if the dependent test’s setup changes. Mitigation: Add health checks for critical dependency chains. |
Testing Strategy:
@depends? Prioritize these for migration to leverage the new converter.Infrastructure:
main branch updates.)Team Adoption:
uses()/beforeEach()? If not, budget time for training or documentation.@dataProvider)? (e.g., manual refactoring, feature requests to the plugin.)@depends tests) or big-bang?Pest + Laravel:
get('/api/users')->assertOk()).uses(DatabaseTransactions::class)).Artisan::call('migrate')).depends converter extends compatibility with PHPUnit’s test dependency patterns, making Pest a viable replacement for teams using:
@depends for setup/teardown.@beforeClass/@afterClass (converted to beforeAll()/afterAll() in Pest).Snapshot Formats:
@depends to chain requests (e.g., auth → resource creation).Tooling Compatibility:
pest-converter: Automates @depends translation.@depends:
grep -r "@depends" tests/ | wc -l
@dataProvider, custom traits, orHow can I help you explore Laravel packages today?