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 components (e.g., Illuminate\Foundation\Application) to bootstrap a test environment, making it ideal for packages targeting Laravel ecosystems.
  • Modular Design: Supports extensibility via traits (WithFixtures, WithConfig), attributes (#[UsesVendor]), and plugins (BrowserKit, Dusk, Workbench). This modularity allows TPMs to tailor testing to specific package needs (e.g., UI testing, database fixtures).
  • Isolation: Designed to reset state between tests (e.g., flushState(), TerminatingConsole), mitigating test pollution—a critical requirement for CI/CD pipelines and parallel testing.

Integration Feasibility

  • Low Friction: Requires minimal setup (e.g., composer require orchestra/testbench-core). Compatibility matrix ensures version alignment with Laravel (e.g., v11.x for Laravel 13.x), reducing versioning conflicts.
  • Package-Specific Testing: Core feature—package:test command—simulates a Laravel app within a package repo, enabling isolated testing of package logic (e.g., service providers, commands) without requiring a full Laravel install.
  • Database/Artisan Support: Supports migrations, seeders, and Artisan commands natively, critical for packages interacting with Laravel’s database layer or CLI tools.

Technical Risk

  • Laravel Version Lock-In: Tight coupling to Laravel versions may require frequent updates (e.g., v11.x for Laravel 13.x). Risk mitigated by active maintenance (releases every 3–6 months).
  • PHPUnit/PestPHP Dependencies: Requires PHPUnit 12.x/13.x or PestPHP. TPMs must ensure test runners align with Testbench’s supported versions.
  • State Management: Advanced features (e.g., flushState()) may introduce complexity for teams unfamiliar with Laravel’s service container or testing quirks. Documentation is thorough but assumes PHP/Laravel familiarity.
  • Parallel Testing: Fixed in recent versions (v10.11.0+), but older versions may require manual configuration for parallel test suites.

Key Questions for TPMs

  1. Laravel Version Strategy:
    • Is the package targeting a specific Laravel LTS version (e.g., 10.x, 11.x)? Testbench’s versioning must align (e.g., v10.x for Laravel 12.x).
    • How will you handle Laravel minor/patch updates? Testbench’s compatibility matrix should be monitored.
  2. Testing Scope:
    • Are tests limited to package logic (e.g., service providers), or do they include UI/API interactions? Extensions like testbench-browser-kit or testbench-dusk may be needed.
    • Do tests require database interactions? Testbench supports migrations/seeders but may need custom fixtures.
  3. CI/CD Integration:
    • How will Testbench be integrated into CI pipelines? The package:test command simplifies this, but parallel testing may require configuration (e.g., PHPUnit --parallel).
    • Are there third-party dependencies (e.g., Chrome for Dusk) that need CI setup (e.g., Docker, Sauce Labs)?
  4. State Isolation:
    • Are there shared state risks (e.g., static caches, singleton services) between tests? Testbench’s flushState() and TerminatingConsole address this, but custom logic may be needed.
  5. Developer Ramp-Up:
    • What’s the team’s familiarity with Laravel testing? Testbench abstracts complexity but assumes knowledge of Laravel’s service container, Artisan, and testing conventions.
  6. Alternatives:
    • For non-Laravel packages, would PestPHP’s native features or a lighter framework (e.g., PHPUnit + Mockery) suffice? Testbench’s value is Laravel-specific.

Integration Approach

Stack Fit

  • Primary Use Case: Laravel packages (e.g., auth systems, payment gateways, CMS plugins) where testing requires a full Laravel environment.
  • Complementary Tools:
    • BrowserKit/Dusk: For UI/API testing (e.g., form submissions, redirects).
    • Workbench: For local package previews (e.g., debugging views/routes).
    • PestPHP: If the team prefers Pest over PHPUnit (Testbench supports both).
  • Avoid When:
    • Testing non-Laravel PHP logic (e.g., standalone CLI tools, microservices).
    • Performance-critical tests (Testbench adds ~10–30% overhead vs. native Laravel testing).

Migration Path

  1. Assessment Phase:
    • Audit existing tests for Laravel dependencies (e.g., Artisan, Route, DB).
    • Identify gaps (e.g., missing migrations, service provider tests).
  2. Setup:
    • Add Testbench to composer.json:
      "require-dev": {
        "orchestra/testbench-core": "^11.0",
        "orchestra/testbench-browser-kit": "^5.0" // if needed
      }
      
    • Configure testbench.yaml (optional) for global settings (e.g., seeders, parallel testing).
  3. Incremental Adoption:
    • Phase 1: Replace manual Laravel bootstrapping (e.g., new Application) with Testbench’s createApplication().
    • Phase 2: Migrate tests to use Testbench traits/attributes (e.g., #[UsesVendor], WithFixtures).
    • Phase 3: Add package-specific tests (e.g., package:publish commands, service provider bindings).
  4. CI/CD Update:
    • Replace custom Laravel test containers with Testbench’s package:test command.
    • Example GitHub Actions snippet:
      - name: Run Tests
        run: vendor/bin/phpunit --testdox-html coverage.html
      
      or for Pest:
      - name: Run Pest
        run: vendor/bin/pest --parallel
      

Compatibility

  • Laravel Versions: Strict 1:1 mapping (e.g., Laravel 13.x → Testbench 11.x). Verify compatibility in the version table.
  • PHPUnit/PestPHP: Supports PHPUnit 12.x/13.x and PestPHP. Ensure phpunit.xml or pest.php config aligns with Testbench’s expectations (e.g., bootstrap paths).
  • Dependencies:
    • Symfony Polyfill: Required for PHP 8.3+ (handled automatically via symfony/polyfill-php84).
    • Chrome/Driver: Only for Dusk (configure via testbench-dusk).
    • Database: Testbench supports SQLite/MySQL/PostgreSQL via Laravel’s .env config.

Sequencing

  1. Core Testing:
    • Start with package logic (e.g., service providers, commands) using createApplication().
    • Example:
      use Orchestra\Testbench\TestCase;
      
      class MyPackageTest extends TestCase {
          protected function getPackageProviders($app) {
              return ['MyPackage\\Providers\\MyServiceProvider'];
          }
      
          public function test_service_provider_registers() {
              $this->assertTrue(true); // Replace with actual assertions
          }
      }
      
  2. Database Testing:
    • Use migrations/seeders via testbench.yaml or WithFixtures trait.
    • Example testbench.yaml:
      seeders: true
      migrations: database/migrations
      
  3. UI/API Testing:
    • Add BrowserKit/Dusk for form/route interactions.
    • Example Dusk test:
      use Orchestra\Testbench\BrowserKit\TestCase;
      
      class MyPackageDuskTest extends TestCase {
          public function test_form_submission() {
              $this->browse(function ($browser) {
                  $browser->visit('/my-package/form')
                          ->type('email', 'test@example.com')
                          ->press('Submit')
                          ->assertPathIs('/success');
              });
          }
      }
      
  4. Parallel Testing:
    • Enable in phpunit.xml:
      <phpunit parallel="true" />
      
    • Ensure WithFixtures is compatible (fixed in v10.11.0+).

Operational Impact

Maintenance

  • Proactive Updates:
    • Monitor Testbench’s release notes for Laravel version support.
    • Example: Upgrade from Laravel 12.x to 13.x requires Testbench v11.x.
  • Dependency Management:
    • Testbench auto-updates with Laravel minor/patch releases (e.g., Laravel 13.9.0 → Testbench 11.3.3).
    • Lock versions in composer.json to avoid surprises:
      "orchestra/testbench-core": "^11.0"
      
  • Deprecations:
    • Recent removals (e.g
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