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.
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.xml configurations, assertions). The package extends PHPUnit’s capabilities without reinventing core testing logic.create(), assertDatabaseHas()).composer require --dev) and no namespace collisions (uses GrahamCampbell\TestBench).| 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. |
Testing Strategy Alignment:
Dependency Management:
CI/CD Impact:
phpunit --parallel)? Traits may need thread-safe adjustments.Long-Term Maintenance:
Developer Adoption:
FacadeTrait vs. Laravel’s RefreshDatabase)?| 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. |
Assessment Phase (1–2 days):
app()->make()).Installation (30 mins):
composer require --dev graham-campbell/testbench-core:^4.3
phpunit.xml to ensure PHPUnit 12 compatibility:
<phpunit ...>
<extensions>
<extension class="GrahamCampbell\TestBench\Extensions\TestBenchExtension"/>
</extensions>
</phpunit>
Incremental Adoption (1–2 weeks):
MockeryTrait.ServiceProviderTrait.FacadeTrait for facade-heavy tests (e.g., auth, caching).// 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);
}
CI/CD Integration (1 day):
Artisan::call() alongside traits.QueueTestCase (Laravel) or MockeryTrait.EventsTestCase and supplement with MockeryTrait for event listeners.How can I help you explore Laravel packages today?