orchestra/testbench
Orchestra Testbench is the de-facto Laravel testing helper for package development. It boots a lightweight Laravel app for your package’s tests, making it easy to run PHPUnit/Pest suites with proper service providers, config, and environment setup.
WithFixtures trait), mocking (via InteractsWithMockery), and state management (e.g., flushing Model, Validator, Str states).--parallel flag (critical for CI/CD pipelines).orchestra/testbench-core (v11.2.0+ for v11.x).mockery/mockery (for mocking) – may require PHP 8.1+.symfony/process (for remote() function) – stable but version-locked.WithFixtures trait).| Risk Area | Severity | Mitigation |
|---|---|---|
| Version Skew | High | Lock Testbench to a specific minor version (e.g., ^11.1) to avoid breaking changes (e.g., Laravel 13+ support in v11.0.0). |
| State Management | Medium | Testbench flushes most states, but custom package globals (e.g., static caches) may leak. Use flushState() or terminate() explicitly. |
| Parallel Test Failures | Medium | --parallel works but may fail with WithFixtures (fixed in v10.11.0+). Test with phpunit --parallel early. |
| Deprecated APIs | Low | v11.0.0+ removed annotations (@define-env, etc.). Migrate to testbench.yaml or traits. |
| CI/CD Flakiness | Low | Use Orchestra\Testbench\terminate() in setUp() to ensure clean exits in CI. |
orchestra/testbench:^10.11.--parallel compatibility early.WithFixtures but may require custom setup for complex schemas.testbench.yaml.| Current State | Migration Steps |
|---|---|
| No Testing | 1. Add orchestra/testbench to devDependencies.2. Extend Orchestra\Testbench\PHPUnit\TestCase.3. Use createApplication() to bootstrap Laravel.4. Write tests with WithFixtures/Mockery. |
| Basic PHPUnit | 1. Replace PHPUnit\Framework\TestCase with Orchestra\Testbench\PHPUnit\TestCase.2. Add use Orchestra\Testbench\Concerns\WithFixtures.3. Configure testbench.yaml for fixtures/providers. |
| Custom Laravel App Tests | 1. Replace artisan test with Testbench’s createApplication().2. Migrate fixtures to Testbench’s WithFixtures.3. Remove global app state dependencies (e.g., cached config). |
| PestPHP | 1. Use Orchestra\Testbench\Concerns\InteractsWithPest.2. Extend Orchestra\Testbench\Pest\TestCase.3. Configure testbench.yaml for Pest-specific overrides. |
| Testbench Version | Laravel Support | PHPUnit Support |
|---|---|---|
| v11.x | 13.x | 13.1+ |
| v10.x | 12.24.0–12.55.0 | 12.5–13.0 |
| v9.x | 11.44.7–11.50.0 | 12.2–12.5 |
.env overrides).WithFixtures for test data.WithFixtures).InteractsWithPest trait).composer.json:
"devDependencies": {
"orchestra/testbench": "^11.1",
"phpunit/phpunit": "^13.1"
}
testbench.yaml (optional but recommended):
fixtures: true
seeders: ["DatabaseSeeder"]
providers: ["YourPackageServiceProvider"]
use
How can I help you explore Laravel packages today?