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.
Illuminate\Foundation\Application) to bootstrap a test environment, making it ideal for packages targeting Laravel ecosystems.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).flushState(), TerminatingConsole), mitigating test pollution—a critical requirement for CI/CD pipelines and parallel testing.composer require orchestra/testbench-core). Compatibility matrix ensures version alignment with Laravel (e.g., v11.x for Laravel 13.x), reducing versioning conflicts.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.flushState()) may introduce complexity for teams unfamiliar with Laravel’s service container or testing quirks. Documentation is thorough but assumes PHP/Laravel familiarity.testbench-browser-kit or testbench-dusk may be needed.package:test command simplifies this, but parallel testing may require configuration (e.g., PHPUnit --parallel).flushState() and TerminatingConsole address this, but custom logic may be needed.Artisan, Route, DB).composer.json:
"require-dev": {
"orchestra/testbench-core": "^11.0",
"orchestra/testbench-browser-kit": "^5.0" // if needed
}
testbench.yaml (optional) for global settings (e.g., seeders, parallel testing).new Application) with Testbench’s createApplication().#[UsesVendor], WithFixtures).package:publish commands, service provider bindings).package:test command.- name: Run Tests
run: vendor/bin/phpunit --testdox-html coverage.html
or for Pest:
- name: Run Pest
run: vendor/bin/pest --parallel
phpunit.xml or pest.php config aligns with Testbench’s expectations (e.g., bootstrap paths).symfony/polyfill-php84).testbench-dusk)..env config.createApplication().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
}
}
testbench.yaml or WithFixtures trait.testbench.yaml:
seeders: true
migrations: database/migrations
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');
});
}
}
phpunit.xml:
<phpunit parallel="true" />
WithFixtures is compatible (fixed in v10.11.0+).composer.json to avoid surprises:
"orchestra/testbench-core": "^11.0"
How can I help you explore Laravel packages today?