Weave Code
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

Pest Plugin Drift Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • 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:

    • Reducing migration friction: The @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).
    • Pest-first philosophy: While the feature is opt-in, it signals a push toward Pest as a drop-in replacement for PHPUnit, leveraging Laravel’s native support for Pest (e.g., HTTP testing, database transactions).
    • Limitation: The conversion is not bidirectional—PHPUnit’s @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:

    • Laravel’s HTTP testing (e.g., get(), post() assertions).
    • Database transactions (via Pest’s uses() or beforeEach()).
    • Snapshot storage (filesystem, S3, or custom backends).
    • New Consideration: Teams using Laravel’s Testing facade (e.g., actingAs(), withoutMiddleware()) should verify compatibility with Pest’s uses() syntax for test dependencies.
  • Isolation vs. Coupling:

    • Pros:
      • Decouples snapshot validation from business logic, reducing flakiness in regression tests.
      • The depends conversion localizes migration effort to test dependencies, leaving other assertions intact.
    • Cons:
      • Tight coupling to Pest: The plugin is Pest-only; PHPUnit users must migrate first.
      • Snapshot storage dependency: Centralized storage (e.g., S3) becomes a single point of failure for drift tests.
      • New Risk: Circular dependencies in converted @depends tests may cause silent failures if not validated during migration.

Integration Feasibility

  • 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
        ],
    ];
    
    • Prerequisites:
      • Pest 2.0+ (for uses()/beforeEach() support).
      • mandisma/pest-converter (v0.2.0+) for annotation parsing.
    • Migration Path:
      • Automated: The converter handles @depends translation but skips unsupported annotations (e.g., @dataProvider).
      • Manual: Teams must refactor remaining tests to Pest syntax.
  • Snapshot Storage: Unchanged. Storage backends (filesystem, database, S3) remain configurable, but large-scale teams should evaluate:

    • Performance: Parallel test execution (Pest’s --parallel) may increase snapshot I/O contention.
    • New: Snapshot versioning (e.g., Git LFS or a dedicated service like Snapshot Testing for PHP) to avoid merge conflicts in CI.
  • CI/CD Readiness:

    • New Workflow Step: Add @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
      
    • Failure Modes:
      • Unsupported Annotations: Tests with @dataProvider or custom PHPUnit traits will fail silently unless pre-validated.
      • Snapshot Updates: Requires explicit approval in CI (e.g., pest --update-snapshots) to avoid accidental merges.

Technical Risk

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.

Key Questions

  1. Testing Strategy:

    • Updated: Which PHPUnit tests rely on @depends? Prioritize these for migration to leverage the new converter.
    • New: How will you validate converted dependencies? (e.g., static analysis, manual review?)
    • Snapshot Scope: Will drift testing cover all layers (unit, feature, API) or focus on high-churn components (e.g., API responses)?
  2. Infrastructure:

    • Updated: Where will snapshots be stored? (Local, S3, custom DB?) New: For distributed teams, will you use centralized storage (e.g., S3) or per-repo snapshots?
    • CI/CD: How will you gate snapshot updates? (e.g., require manual approval for main branch updates.)
    • New: Will you cache snapshots in CI to reduce I/O? (e.g., GitHub Actions cache for local filesystem storage.)
  3. Team Adoption:

    • Updated: Are developers familiar with Pest’s uses()/beforeEach()? If not, budget time for training or documentation.
    • New: How will you handle unsupported PHPUnit features (e.g., @dataProvider)? (e.g., manual refactoring, feature requests to the plugin.)
    • Migration Timeline: Will you phase migration (e.g., start with @depends tests) or big-bang?

Integration Approach

Stack Fit

  • Pest + Laravel:

    • Native Support: Unchanged. Pest integrates with Laravel’s:
      • HTTP testing (get('/api/users')->assertOk()).
      • Database transactions (uses(DatabaseTransactions::class)).
      • Artisan commands (Artisan::call('migrate')).
    • New: The 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:

    • Unchanged. Supports JSON, HTML, XML, and custom formats.
    • New Use Case: API contract testing (e.g., OpenAPI specs) can now leverage @depends to chain requests (e.g., auth → resource creation).
  • Tooling Compatibility:

    • CI/CD: Unchanged. Integrates with GitHub/GitLab merge queues.
    • IDE: Unchanged. VS Code’s GitLens supports snapshot diffs.
    • New: Migration Tools:
      • pest-converter: Automates @depends translation.
      • Static Analyzers: Tools like PHPStan can pre-check for unsupported annotations.

Migration Path

  1. Phase 0: Pre-Migration Audit
    • New: Identify PHPUnit tests with @depends:
      grep -r "@depends" tests/ | wc -l
      
    • Blockers: Flag tests with @dataProvider, custom traits, or
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.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium