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

graham-campbell/testbench-core

Core testing utilities for Laravel packages, maintained by Graham Campbell. Provides lightweight TestBench components compatible with Laravel 8–13, PHP 7.4–8.5, and PHPUnit 9–12 to simplify package test setup and integration.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Core Testing Utilities for Laravel: The package provides traits for common testing patterns (e.g., FacadeTrait, ServiceProviderTrait, MockeryTrait), aligning with Laravel’s dependency injection (DI) and facade-based architecture. This is a natural fit for Laravel applications, especially those with modular components, plugins, or microservices.
  • PHPUnit Integration: Leverages PHPUnit 9–12, ensuring compatibility with Laravel’s testing ecosystem (e.g., phpunit.xml configurations, assertions). The package extends PHPUnit’s capabilities without reinventing core testing logic.
  • Trait-Based Design: Encourages composition over inheritance, reducing test class bloat and improving reusability across test suites. Ideal for large codebases where test duplication is a pain point.
  • Limited Overhead: No service providers or configuration required—zero runtime impact in production, making it purely a development-time tool.

Integration Feasibility

  • Laravel Version Support: Covers Laravel 8–13, which includes ~90% of active Laravel projects (as of 2024). Backward compatibility with older versions (e.g., 5.5–8) via older package versions reduces migration friction.
  • PHPUnit Dependency: Requires PHPUnit 9–12, which is standard in modern Laravel projects. No conflicts with Laravel’s built-in testing helpers (e.g., create(), assertDatabaseHas()).
  • Composer Integration: Zero-config installation (composer require --dev) and no namespace collisions (uses GrahamCampbell\TestBench).
  • Mockery Support: Works alongside Laravel’s Mockery integration, enabling advanced mocking for services, repositories, and facades.

Technical Risk

Risk Area Assessment Mitigation Strategy
Breaking Changes Minor API shifts (e.g., static methods in v4.0) but clear deprecation paths. Risk is low for teams on Laravel 8+. Pin to v4.3.x for stability; monitor PHPUnit 13 adoption for future compatibility.
Mockery Deprecation Mockery is deprecated in PHPUnit 10+, but the package adapts (e.g., MockeryTrait fixes in v4.2.1). Risk is moderate if relying heavily on Mockery. Gradually migrate to PHPUnit’s native mocking or PestPHP (if adopting).
Laravel 14+ Support No official support for Laravel 14 yet. Risk if upgrading soon. Monitor Graham Campbell’s roadmap; consider forking if critical.
Test Flakiness Traits like ServiceProviderTrait may mask edge cases in service binding tests. Risk if over-relying on abstractions. Supplement with manual assertions or PestPHP’s fluent syntax for complex scenarios.
Performance Impact None in production; minimal test suite overhead (traits add <5ms to test execution). Benchmark in CI pipelines to ensure no regressions.

Key Questions for Stakeholders

  1. Testing Strategy Alignment:

    • Does the team prioritize trait-based testing (composition) over class-based test suites? If not, the package may require additional wrappers.
    • Are there existing custom testing utilities that could conflict with this package’s traits?
  2. Dependency Management:

    • Is PHPUnit 12 the minimum viable version for the team? If not, v3.4 (PHPUnit 9–10) may be needed.
    • How is Mockery currently used? If heavily relied upon, the deprecation risk should be addressed proactively.
  3. CI/CD Impact:

    • Will this reduce test flakiness in CI, or introduce new edge cases (e.g., facade resolution in tests)?
    • Does the team use parallel test execution (e.g., phpunit --parallel)? Traits may need thread-safe adjustments.
  4. Long-Term Maintenance:

    • Is there budget for commercial support (via Tidelift) if critical bugs arise?
    • How will the team handle Laravel 14+ upgrades? Will a custom fork be necessary?
  5. Developer Adoption:

    • Will the team train developers on the package’s traits (e.g., FacadeTrait vs. Laravel’s RefreshDatabase)?
    • Are there legacy tests that would need refactoring to use the new traits?

Integration Approach

Stack Fit

  • Primary Use Case: Laravel applications (8–13) using PHPUnit 9–12 for unit, feature, and integration tests.
  • Secondary Use Case: Laravel packages/plugins needing standardized testing patterns (e.g., service providers, facades).
  • Compatibility Matrix:
    Component Fit Notes
    Laravel 8–13 Native Uses Laravel’s service container, facades, and DI.
    PHPUnit 9–12 Native Extends PHPUnit’s assertions and test lifecycle.
    Mockery Supported Via MockeryTrait (with deprecation awareness).
    PestPHP ⚠️ Partial Can coexist but may require custom assertions.
    Livewire/Inertia Works Traits like ServiceProviderTrait help test frontend-backend integration.
    API Testing (Pest) ⚠️ Manual Setup No built-in HTTP helpers; pair with Pest’s HTTP tests.
    Database Testing ⚠️ Complementary Use with Laravel’s DatabaseMigrations, DatabaseTransactions.

Migration Path

  1. Assessment Phase (1–2 days):

    • Audit existing test suite for:
      • Custom mocking/service provider logic.
      • Facade resolution patterns (e.g., app()->make()).
      • PHPUnit/Mockery versions.
    • Identify high-priority test classes for refactoring (e.g., service provider tests, API contract tests).
  2. Installation (30 mins):

    composer require --dev graham-campbell/testbench-core:^4.3
    
    • Update phpunit.xml to ensure PHPUnit 12 compatibility:
      <phpunit ...>
          <extensions>
              <extension class="GrahamCampbell\TestBench\Extensions\TestBenchExtension"/>
          </extensions>
      </phpunit>
      
  3. Incremental Adoption (1–2 weeks):

    • Phase 1: Replace custom mocking with MockeryTrait.
    • Phase 2: Refactor service provider tests to use ServiceProviderTrait.
    • Phase 3: Adopt FacadeTrait for facade-heavy tests (e.g., auth, caching).
    • Example refactor:
      // Before (custom)
      public function testServiceProvider()
      {
          $provider = new MyServiceProvider(app());
          $this->assertInstanceOf(MyService::class, $provider->register());
      }
      
      // After (using trait)
      use GrahamCampbell\TestBench\Traits\ServiceProviderTrait;
      
      public function testServiceProvider()
      {
          $this->assertServiceProviderRegistered(MyServiceProvider::class);
          $this->assertServiceBound(MyService::class);
      }
      
  4. CI/CD Integration (1 day):

    • Update test workflows to include the package.
    • Add static analysis (e.g., PHPStan) to catch trait usage issues.

Compatibility Considerations

  • Laravel Artisan Commands: If testing console commands, use Laravel’s built-in Artisan::call() alongside traits.
  • Queues/Jobs: For queued job tests, combine with QueueTestCase (Laravel) or MockeryTrait.
  • Event Testing: Use Laravel’s EventsTestCase and supplement with MockeryTrait for event listeners.
  • Legacy Code: For pre-Laravel 8 apps,
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.
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
anil/file-picker
broqit/fields-ai