orchestra/testbench-core
Testbench Core is the foundation for Orchestra Testbench, providing a lightweight Laravel application bootstrap for package testing. Run artisan commands, migrations, factories, and routes in your test suite with versioned Laravel compatibility.
TerminatingConsole, fixture loading, and state flushing (e.g., Str, Validator) address common Laravel testing pain points (e.g., shared state pollution, artisan command testing). This is critical for packages with global state dependencies (e.g., caching, queues).testbench.yaml config and WithFixtures trait enable package-aware testing, which is essential for TPMs building composable Laravel packages (e.g., auth systems, payment gateways).composer.json (e.g., "orchestra/testbench-core": "^11.0").Orchestra\Testbench\PHPUnit\TestCase for base tests.testbench.php for package-specific needs (e.g., custom migrations, providers).php artisan mypackage:generate).^ in composer.json and pin to a specific minor version (e.g., 10.x-dev) for stability.WithFixtures trait has known issues with --parallel in PHPUnit (fixed in v11.0.1+). TPMs using parallel test suites must:
refreshDatabase() per test.@define-env, @define-db) and classes (Env, HandleTerminatingConsole). TPMs with legacy test suites may need refactoring.
testbench.yaml for modern config.Str, Validator, and JsonResource states, custom package state (e.g., singleton services) may still leak. TPMs must:
refreshApplication() or refreshMigrations() sparingly.App::singleton() bindings) explicitly.--parallel) be used? If yes, confirm Testbench Core ≥ v11.0.1.@define-env)? Budget time for migration to testbench.yaml.$app->setKernel()).WithFixtures to avoid full app bootstrapping where possible.testbench.php config, but TPMs must validate:
| Tool | Compatibility | Notes |
|---|---|---|
| PHPUnit | ✅ Full support (v12/13) | Use Orchestra\Testbench\PHPUnit\TestCase. |
| PestPHP | ✅ Partial (via testbench.yaml) |
Requires config for Pest integration. |
| Laravel Dusk | ✅ (via Testbench Dusk) | Adds ChromeDriver dependency. |
| BrowserKit | ✅ (via Testbench BrowserKit) | No JS support. |
@define-env, @define-db).composer require --dev orchestra/testbench-core ^11.0
testbench.php (if using custom config):
<?php
return [
'migrations' => 'path/to/migrations',
'providers' => [
// Custom providers
],
'seeders' => true, // Enable if using database seeding
];
use Orchestra\Testbench\PHPUnit\TestCase;
class MyPackageTest extends TestCase { ... }
@define-env with testbench.php config).# GitHub Actions example
- run: php artisan testbench
TESTBENCH_USER_MODEL).testbench.php:
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
],
],
How can I help you explore Laravel packages today?