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 Core Laravel Package

orchestra/testbench-core

Orchestra Testbench Core is the foundation for testing Laravel packages. It boots a lightweight Laravel app inside your package so you can run artisan commands, migrations, routing, and more, with compatibility across Laravel 6–12.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel-Native Integration: Testbench Core is purpose-built for Laravel, aligning seamlessly with its architecture (e.g., service providers, migrations, Artisan commands, and routing). It leverages Laravel’s core testing utilities (PHPUnit/PestPHP) while abstracting boilerplate setup.
  • Package Testing Focus: Ideal for Laravel package developers (e.g., Spatie, Laravel Shift) needing to test isolated functionality without requiring a full Laravel install. Supports attribute-based testing (e.g., @WithConfig, #[UsesVendor]) and fixture management.
  • Extensibility: Core package is modular—extends via Testbench, Testbench-BrowserKit, or Testbench-Dusk for UI/JS testing. Supports custom test skeletons and parallel test execution.

Integration Feasibility

  • Low Friction: Replaces manual Laravel app bootstrapping in tests (e.g., BootstrapApplication, LoadEnvironmentVariables). Provides package:test CLI command to scaffold test environments.
  • Dependency Management: Explicit Laravel version compatibility (v6–v13) ensures no breaking conflicts. PHPUnit/PestPHP integration is battle-tested.
  • Configuration Overrides: Supports dynamic config merging (e.g., WithConfig attribute) and service provider disabling, critical for package testing.

Technical Risk

  • Laravel Version Lock: Tight coupling to Laravel versions may require parallel maintenance if upgrading Laravel. Example: PHP 8.5+ support in v10.8.0+.
  • Deprecation Risk: Removal of annotations (@define-env, @define-db) in v11.0.0+ may impact legacy tests. Migration path exists but requires refactoring.
  • Parallel Testing Quirks: --parallel flag has known issues with WithFixtures (fixed in v11.0.1), requiring validation for CI/CD pipelines.
  • State Management: Global state (e.g., Str, Validator, JsonResource) is flushed per-test, but custom stateful services may need explicit cleanup.

Key Questions

  1. Laravel Version Strategy:
    • Is the target Laravel version (e.g., v12+) supported by the latest Testbench Core (v11.x)?
    • How will minor Laravel upgrades (e.g., v12.x → v13.x) be handled without breaking tests?
  2. Testing Scope:
    • Are tests package-focused (recommended) or full-stack (may need Testbench-Dusk)?
    • Will custom service providers or event listeners require special setup?
  3. CI/CD Impact:
    • How will parallel test execution (PHPUnit --parallel) interact with WithFixtures?
    • Are database transactions or seeders needed per-test (configured via testbench.yaml)?
  4. Legacy Code:
    • Are any tests using deprecated annotations (e.g., @define-env) that need migration?
    • Does the codebase rely on global state (e.g., Str::macro()) that may leak between tests?
  5. Performance:
    • Will test isolation (e.g., flushState()) introduce overhead for high-volume test suites?
    • Are asset symlinks (e.g., public/ folder) required for testing (handled by Workbench)?

Integration Approach

Stack Fit

  • Primary Use Case: Laravel package development (e.g., auth packages, API wrappers, CLI tools).
  • Secondary Use Case: Isolated Laravel feature testing (e.g., testing a single controller/middleware without a full app).
  • Compatibility:
    • PHPUnit/PestPHP: Native support for both, with PestPHP-specific fixes (e.g., $__filename resolution).
    • Laravel Artifacts: Supports migrations, factories, seeders, and Artisan commands natively.
    • UI Testing: Extend with Testbench-BrowserKit (non-JS) or Testbench-Dusk (JS-enabled).
  • Alternatives Considered:
    • Laravel’s Native Testing: More verbose for packages; lacks package-specific utilities (e.g., UsesVendor).
    • PestPHP Standalone: Lighter but lacks Laravel-specific helpers (e.g., WithMigrations).

Migration Path

  1. Adoption Phases:
    • Phase 1: Replace manual BootstrapApplication with Testbench base class.
    • Phase 2: Migrate to attributes (e.g., #[WithConfig]) for cleaner test setup.
    • Phase 3: Adopt testbench.yaml for centralized config (e.g., seeders, providers).
  2. Incremental Rollout:
    • Start with unit tests (e.g., services, commands) → feature tests (e.g., controllers) → UI tests (if needed).
    • Use package:test CLI to scaffold initial test structure.
  3. Legacy Migration:
    • Replace deprecated annotations with attributes (e.g., @define-env#[WithEnvironment]).
    • Update global state handling (e.g., Str::macro()) to use flushState().

Compatibility

Component Compatibility Notes
Laravel v12–v13 ✅ Full support (v11.x Testbench Core) Check composer.json constraints.
PHPUnit 12–13 ✅ Native support PestPHP support included.
Custom Service Providers ✅ Via WithProviders attribute Supports disabling default Laravel providers.
Database Testing WithMigrations, WithFactories, WithSeeders Transactions auto-rolled back.
UI Testing Testbench-BrowserKit (non-JS) / Testbench-Dusk (JS) Requires additional packages.
Parallel Testing ⚠️ Works but validate WithFixtures (fixed in v11.0.1+) CI/CD may need --parallel adjustments.

Sequencing

  1. Prerequisites:
    • Align Laravel version in composer.json with Testbench Core’s matrix.
    • Install orchestra/testbench-core and optional extensions (e.g., orchestra/testbench-browser-kit).
  2. Test Structure:
    # Scaffold tests
    vendor/bin/package:test
    
    • Organize tests by feature (e.g., tests/Features/Auth, tests/Unit/Services).
  3. Configuration:
    • Define testbench.yaml for shared settings (e.g., seeders, providers).
    • Example:
      seeders: true
      providers:
        - App\Providers\AuthServiceProvider
      
  4. Test Conversion:
    • Replace BootstrapApplication with:
      use Orchestra\Testbench\TestCase;
      
      class MyTest extends TestCase { ... }
      
    • Migrate annotations to attributes:
      #[WithConfig(['app.timezone' => 'UTC'])]
      
  5. Validation:
    • Run tests with --parallel flag in CI to catch edge cases.
    • Verify flushState() covers custom global state.

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Eliminates manual Laravel app setup per test.
    • Centralized Config: testbench.yaml manages shared test settings.
    • Active Development: Frequent updates (e.g., PHP 8.5, Laravel 13 support).
  • Cons:
    • Dependency Bloat: Core package + extensions may increase CI/CD build times.
    • Version Chore: Requires parallel maintenance for Laravel upgrades (e.g., v12 → v13).
  • Long-Term Costs:
    • Test Refactoring: Migration from annotations to attributes (one-time cost).
    • State Management: Custom stateful services may need explicit cleanup.

Support

  • Debugging:
    • Test Isolation: Global state flushing reduces flaky tests but may mask issues in custom services.
    • Error Handling: Clear error messages for missing providers/configs (e.g., BindingResolutionException).
  • Community:
    • Active Issues: GitHub issues are responsive (e.g., parallel testing fixes).
    • Documentation: README and release notes are comprehensive but lack deep-dive guides for advanced use cases (e.g., custom state management).
  • Vendor Lock-in:
    • Low risk; MIT license and open-source. Alternatives (e.g., PestPHP) lack Laravel-specific helpers.

Scaling

  • Performance:
    • Test Speed: Minimal overhead for unit tests; UI tests (Testbench-Dusk) add ~2–5x runtime.
    • Parallel Testing: Supported but validate `With
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