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

Testbench Laravel Package

graham-campbell/testbench

Testing utilities for Laravel packages, built on PHPUnit, Mockery, Orchestral Testbench, and Laravel Testbench Core. Supports Laravel 8–13 and PHP 7.4–8.5, with compatibility for PHPUnit 9–11 to help you run fast, reliable package test suites.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Laravel-Centric: Built specifically for Laravel, leveraging its ecosystem (e.g., service providers, migrations, queues) while abstracting boilerplate. Aligns with Laravel’s testing patterns (e.g., AbstractTestCase inheritance).
    • Layered Abstraction: Combines Orchestral Testbench (for package testing) and Laravel Testbench Core (for app testing), offering flexibility for both unit and integration tests.
    • Mockery Integration: Enables mocking dependencies (e.g., repositories, external APIs) without coupling tests to concrete implementations.
    • PHPUnit Compatibility: Supports modern PHPUnit (9–12) and Laravel (8–13), reducing version conflicts in CI/CD pipelines.
    • No Configuration Overhead: Zero setup required beyond installation, unlike frameworks like Pest or Laravel’s built-in testing tools that may need additional configuration.
  • Weaknesses:

    • Dependency on External Packages: Relies on Orchestral Testbench and Mockery, adding indirect dependencies that must be maintained.
    • Legacy Laravel Support: While modern versions target Laravel 8–13, older versions (e.g., 5.x) may introduce technical debt if adopted for legacy projects.
    • Limited Built-in Assertions: Unlike Pest, it lacks opinionated helpers (e.g., assertSoftDeleted, assertDatabaseHas), requiring manual assertions for common Laravel patterns.

Integration Feasibility

  • Stack Fit:

    • Ideal for: Teams using Laravel 8–13 with PHPUnit 9–12, especially those developing packages (e.g., Spatie, Laravel packages) or needing isolated test environments.
    • Challenges:
      • Pest Users: If the team uses Pest, TestBench may feel redundant (Pest already includes TestBench-like features). Migration effort would be needed to adopt TestBench’s AbstractTestCase patterns.
      • Legacy Projects: Projects on Laravel <8 or PHP <7.4 would require downgrading TestBench (e.g., v5.x), increasing maintenance risk.
    • Toolchain Synergy:
      • Works seamlessly with Laravel Mix, Forge, and Envoyer for CI/CD (e.g., GitHub Actions, CircleCI).
      • Compatible with Laravel Debugbar and Telescope for test debugging.
  • Technical Risk:

    • Low Risk: Minimal risk for greenfield projects on Laravel 8+. Risks increase for:
      • Projects with custom test runners (e.g., custom PHPUnit bootstrapping).
      • Teams using alternative mocking libraries (e.g., PHPUnit’s native mocks).
    • Breaking Changes: v6.0+ removed backward compatibility for older Laravel/PHP versions, so adoption must align with the team’s stack.

Key Questions for TPM

  1. Testing Strategy:
    • Is the team using package testing (e.g., testing a Laravel package in isolation) or application testing? TestBench excels at the former.
    • Are there existing test suites (e.g., Pest, custom PHPUnit) that would conflict or require refactoring?
  2. Stack Alignment:
    • What Laravel/PHPUnit versions are in use? TestBench’s matrix (e.g., v6.3 for Laravel 13) must match.
    • Is Mockery already in use, or would its addition require dependency updates?
  3. CI/CD Impact:
    • How are tests currently run (e.g., parallelization, coverage tools)? TestBench adds no overhead but may require adjusting phpunit.xml.
  4. Developer Ramp-Up:
    • Are developers familiar with TestBench’s AbstractTestCase or will training be needed?
    • Is there a preference for opinionated helpers (e.g., Pest’s assertDatabaseCount) vs. TestBench’s flexibility?
  5. Long-Term Maintenance:
    • Who maintains the package (Graham Campbell is active but open-source)? Is commercial support (via Tidelift) a consideration?
    • Are there plans to migrate to Laravel’s built-in testing tools (e.g., Laravel\Testing) or Pest in the future?

Integration Approach

Stack Fit

  • Primary Use Cases:
    1. Package Development: TestBench was designed for Laravel package authors (e.g., testing a package’s service provider without booting a full Laravel app).
    2. Isolated Testing: Simulate a Laravel environment for unit/integration tests without polluting the main app’s database/config.
    3. Mocking Dependencies: Use Mockery to stub external services (e.g., Stripe, Mailgun) in tests.
  • Compatibility:
    • PHPUnit: Requires PHPUnit 9–12 (v12 unsupported due to volatility). Teams using v8 or older must downgrade TestBench.
    • Laravel: Supports 8–13. Projects on older versions (e.g., 7) need v5.x, which may lack modern features.
    • Mockery: Automatically included; no additional setup needed.
    • Orchestral Testbench: Under the hood; provides package-testing utilities.

Migration Path

Current State Migration Steps Risks
No Testing Framework 1. Install TestBench (composer require graham-campbell/testbench --dev).2. Extend AbstractTestCase for package tests or AbstractAppTestCase for app tests.3. Write tests using Mockery/PHPUnit. None; greenfield adoption.
PHPUnit Only 1. Add TestBench.2. Replace custom test bootstrapping with AbstractTestCase.3. Migrate manual mocks to Mockery.4. Update phpunit.xml to include TestBench’s paths. Mockery learning curve; test refactoring.
Pest Framework 1. Evaluate if TestBench’s features (e.g., package testing) are missing in Pest.2. If needed, dual-boot Pest + TestBench or migrate to TestBench-only.3. Refactor tests to use AbstractTestCase. High refactoring cost; Pest may already cover TestBench’s use cases.
Legacy Laravel (<8) 1. Downgrade TestBench to v5.x.2. Update PHPUnit to v8/9.3. Test compatibility with Laravel’s version.4. Gradually migrate to newer Laravel/TestBench versions. Technical debt; security risks from outdated dependencies.
Custom Test Runner 1. Ensure the runner supports TestBench’s AbstractTestCase.2. Update test discovery to include TestBench’s classes.3. Test parallel execution (if used). Integration complexity; may require custom bootstrapping.

Sequencing

  1. Assessment Phase:
    • Audit existing tests for compatibility (e.g., PHPUnit versions, Laravel features used).
    • Identify gaps TestBench fills (e.g., package testing, Mockery).
  2. Pilot Phase:
    • Start with package tests (lowest risk) using AbstractPackageTestCase.
    • Gradually adopt for app tests if needed.
  3. Full Adoption:
    • Replace custom test bootstrapping with TestBench’s AbstractTestCase.
    • Update CI/CD pipelines to include TestBench’s dependencies.
  4. Optimization:
    • Leverage TestBench’s static methods (e.g., getRequiredServiceProviders) to reduce boilerplate.
    • Integrate with Laravel’s testing helpers (e.g., actingAs, assertSession) where possible.

Compatibility Checklist

  • Laravel version is 8–13 (or downgrade TestBench for older versions).
  • PHPUnit version is 9–11 (v12 unsupported).
  • Mockery is not already in use (or is compatible with TestBench’s version).
  • No custom test bootstrapping conflicts with AbstractTestCase.
  • CI/CD environment supports PHP 7.4–8.5.

Operational Impact

Maintenance

  • Pros:
    • Minimal Maintenance: No configuration files or service providers to update. Dependencies are managed via Composer.
    • Active Development: Regular updates (e.g., Laravel 13 support in v6.3) and security patches (MIT license).
    • Community Support: Graham Campbell is responsive; Tidelift offers commercial support.
  • Cons:
    • Indirect Dependencies: Orchestral Testbench and Mockery must be maintained. Breaking changes in these libraries could affect TestBench.
    • Version Locking: Must pin TestBench versions to avoid compatibility issues (e.g., PHPUnit 12’s volatility).
    • Deprecation Risk: If Laravel shifts testing focus to built-in tools (e.g., `Laravel\Testing
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.
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
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope