orchestra/testbench
Orchestra Testbench is the de facto helper for testing Laravel packages. It boots a lightweight Laravel app for PHPUnit/Pest, so you can run integration and feature tests against your package with minimal setup and fast feedback.
workbench/bootstrap/providers.php), allowing TPMs to tailor the test environment to package-specific needs (e.g., custom providers, middleware, or database configurations).Model, Validator, Str) between tests, mitigating test pollution—a critical feature for reliable CI/CD pipelines.WithFixtures trait and testbench.yaml configuration simplify database-driven testing, reducing setup time for packages with complex data dependencies.InteractsWithMockery trait streamlines dependency mocking, a common requirement for testing package interactions with external services (e.g., APIs, queues).--parallel compatibility (e.g., v10.11.0) ensures scalability for large test suites, critical for performance-critical packages.#[UsesVendor]) may introduce friction for teams unfamiliar with Pest. Mitigation: Standardize on one testing framework per project.laravel_migration_path() deprecation in v11.0.0). Mitigation: Align package minimum Laravel version with Testbench’s supported range.Laravel Version Strategy:
package_version_compare()) be leveraged?Orchestra\Testbench\package_version_compare() to gate feature tests by Laravel version.Testing Framework Standardization:
#[UsesVendor] attribute) to avoid duplication.CI/CD Pipeline Impact:
WithFixtures trait to isolate database states.Custom Skeleton Design:
spatie/laravel-permission would need its provider in workbench/bootstrap/providers.php.Orchestra\Sidekick\package_path() helps locate package assets dynamically.State Management:
setUp() to flush custom caches: $this->app->flush('my-package-cache').Performance Testing:
Deprecation Handling:
composer.json:
composer require --dev orchestra/testbench
phpunit.xml to extend Testbench’s base configuration:
<extensions>
<extension class="Orchestra\Testbench\PHPUnit\TestbenchServiceProvider"/>
</extensions>
tests/Workbench) with:
providers.php: Package-specific service providers.migrations/: Database fixtures.config/: Overridden Laravel configurations.providers.php:
$app->register(\MyPackage\Providers\MyPackageServiceProvider::class);
tests/Feature/AuthenticationTests.php).use Orchestra\Testbench\Concerns\WithFixtures;
use Orchestra\Testbench\TestCase;
class MyPackageTest extends TestCase
{
use WithFixtures;
protected function getPackageProviders($app)
{
return [\MyPackage\Providers\MyPackageServiceProvider::class];
}
}
tests/Workbench/migrations/ and enable in testbench.yaml:
seeders: true
$this->loadMigrationsFrom([__DIR__.'/Workbench/migrations']);
orchestra/testbench:^11.0 for Laravel 13).#[UsesVendor]).register() method populates the container correctly.WithFixtures.package_version_compare().if (Orchestra\Testbench\package_version_compare('12.0.0', '>=')) {
// Test Laravel 12+ specific features
}
- name: Run tests
run: phpunit --parallel
How can I help you explore Laravel packages today?