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

Phpunit Slow Test Detector Laravel Package

ergebnis/phpunit-slow-test-detector

PHPUnit extension (Composer package and PHAR) that detects and reports slow tests during test runs. Configure a global maximum duration; when tests exceed it, the extension lists them with timings to help you spot and fix performance regressions.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Non-intrusive: Integrates seamlessly as a PHPUnit extension without modifying test logic or CI/CD pipelines.
    • Standardized Output: Provides clear, actionable insights (test durations) in a format compatible with existing CI/CD tools (e.g., GitHub Actions, Jenkins).
    • Configurable Thresholds: Allows customization of "slow" test definitions (e.g., maximum-duration, maximum-count), aligning with team-specific CI/CD constraints.
    • Version Agnostic: Supports PHPUnit 6.5–13.x, ensuring backward compatibility with legacy and modern Laravel projects.
    • MIT License: No legal barriers to adoption.
  • Cons:

    • Limited to PHPUnit: Only applicable to projects using PHPUnit for testing (irrelevant for projects using PestPHP or other test runners).
    • No Native CI Integration: Requires manual parsing of output for advanced use cases (e.g., auto-failing builds on slow tests).

Integration Feasibility

  • Low Effort: Installation via Composer (composer require --dev ergebnis/phpunit-slow-test-detector) and minimal XML configuration.
  • Dependency Risk: No breaking changes to existing dependencies; only adds a PHPUnit extension.
  • Configuration Overhead: Requires updating phpunit.xml (or equivalent) to enable the extension, but this is a one-time setup.

Technical Risk

  • Minimal:
    • Compatibility: Tested against PHPUnit 6.5–13.x; Laravel projects typically use PHPUnit 9.x/10.x, reducing risk.
    • Performance Impact: Negligible overhead during test execution (only measures durations).
    • False Positives/Negatives: Configurable thresholds mitigate misclassification of tests.
  • Potential Pitfalls:
    • CI/CD Pipeline Changes: May require adjustments to test reporting (e.g., parsing stderr for slow tests).
    • Legacy Systems: Projects using PHPUnit <6.5 are unsupported (though unlikely in modern Laravel stacks).

Key Questions

  1. Test Runner Compatibility:
    • Does the project use PHPUnit (not PestPHP or other runners)? If not, this package is irrelevant.
  2. CI/CD Integration:
    • Can the CI system parse the slow-test output (e.g., to fail builds or notify teams)?
    • Example: GitHub Actions workflows may need updated phpunit commands to capture stderr.
  3. Threshold Tuning:
    • What constitutes a "slow" test for the team? Default (500ms) may be too aggressive for some workflows.
  4. Legacy Support:
    • Is the project using PHPUnit <6.5? If so, this package cannot be used.
  5. Monitoring Needs:
    • Should slow tests trigger automated alerts (e.g., Slack notifications) or just be logged?
    • Does the team need historical trend analysis (e.g., tracking test speed degradation over time)?

Integration Approach

Stack Fit

  • Primary Use Case:
    • Laravel Projects: Ideal for teams using PHPUnit (default in Laravel) to identify and optimize slow tests in the test suite.
    • CI/CD Optimization: Reduces flaky test suite feedback loops by surfacing performance bottlenecks.
  • Alternatives Considered:
    • PestPHP: No native support; would require custom logic to replicate functionality.
    • Custom Scripts: Possible but less maintainable than this package.
  • Synergies:
    • Works alongside Laravel Forge, Envoyer, or Deployer for deployment pipelines where test speed impacts release cycles.
    • Complements Laravel Dusk or Pint workflows if tests are part of pre-deployment checks.

Migration Path

  1. Assessment Phase:
    • Verify PHPUnit version compatibility (check composer.json for phpunit/phpunit).
    • Audit CI/CD pipelines to confirm phpunit command usage (e.g., ./vendor/bin/phpunit).
  2. Installation:
    composer require --dev ergebnis/phpunit-slow-test-detector
    
  3. Configuration:
    • Update phpunit.xml (or phpunit.dist.xml) with the extension and desired thresholds:
      <extensions>
          <bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
      </extensions>
      <php>
          <server name="PHPUNIT_SLOW_TEST_DETECTOR_MAXIMUM_DURATION" value="1000"/> <!-- 1s threshold -->
          <server name="PHPUNIT_SLOW_TEST_DETECTOR_MAXIMUM_COUNT" value="5"/>
      </php>
      
  4. CI/CD Adjustment:
    • Modify test commands to capture stderr if needed (e.g., GitHub Actions):
      - run: ./vendor/bin/phpunit --colors=never 2>&1 | tee phpunit.log
      
    • Add post-processing to parse phpunit.log for slow tests (e.g., using grep or a script).
  5. Validation:
    • Run tests locally to verify slow tests are detected.
    • Test CI pipeline with a known slow test to confirm output parsing.

Compatibility

  • Laravel-Specific:
    • No conflicts with Laravel’s default testing setup (uses PHPUnit by default).
    • Works with Laravel Mix, Vite, or Pint if tests are part of the build process.
  • Tooling:
    • GitHub Actions: Requires minor adjustments to capture stderr.
    • Jenkins: May need a post-build step to analyze slow-test output.
    • Parallel Testing: Compatible with PHPUnit’s parallelization (tests are measured individually).

Sequencing

  1. Phase 1: Install and configure the package in development.
  2. Phase 2: Validate locally with a subset of tests.
  3. Phase 3: Integrate into CI/CD pipelines (start with non-critical branches).
  4. Phase 4: Adjust thresholds based on real-world data and team feedback.
  5. Phase 5 (Optional): Automate alerts or build failures for slow tests.

Operational Impact

Maintenance

  • Low Effort:
    • No runtime maintenance; updates via Composer.
    • Configuration is static (thresholds) and rarely needs adjustment.
  • Dependency Updates:
    • Monitor PHPUnit major versions for compatibility (e.g., PHPUnit 14.x support).
    • Check for package updates (e.g., bug fixes for edge cases).

Support

  • Troubleshooting:
    • Common issues:
      • No output: Verify phpunit.xml configuration and PHPUnit version.
      • False positives: Adjust maximum-duration or exclude known slow tests via annotations (if supported).
    • Debugging steps:
      1. Run PHPUnit with -v to confirm extension is loaded.
      2. Check stderr for errors during test execution.
  • Documentation:
    • Limited but sufficient for basic use. May need internal docs for CI/CD integration specifics.

Scaling

  • Performance:
    • Minimal overhead; does not impact test execution speed.
    • Scales with test suite size (no additional resource usage).
  • Large Test Suites:
    • Useful for identifying bottlenecks in feature:tests, unit tests, or integration tests.
    • Can be combined with test filtering (e.g., --group slow) to isolate problematic areas.

Failure Modes

Failure Scenario Impact Mitigation
PHPUnit version incompatibility Extension fails to load Pin PHPUnit version in composer.json
Misconfigured phpunit.xml No slow-test output Validate XML syntax and extension class name
CI pipeline ignores stderr Slow tests go undetected Update pipeline to capture stderr
Threshold too aggressive False positives flood logs Adjust maximum-duration or maximum-count
Test suite flakiness Slow tests mask intermittent failures Combine with other tools (e.g., phpunit --repeat)

Ramp-Up

  • Developer Onboarding:
    • Time: <1 hour to install and configure.
    • Skills Needed: Basic PHPUnit configuration knowledge.
  • Team Adoption:
    • Quick Wins: Immediate visibility into slow tests during local development.
    • CI/CD Impact: May require 1–2 days to integrate into pipelines.
  • Training:
    • Share example phpunit.xml configurations.
    • Document how to interpret slow-test output (e.g., "Tests over 1s are flagged").
  • Change Management:
    • Frame as a quality improvement (not a breaking change).
    • Start with optional use (e.g., --tag slow-test-detection) before enforcing.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony