Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Testbench Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Laravel Testing Helper for Packages Development

Frequently asked questions about Testbench
How do I install orchestra/testbench for Laravel package testing?
Run `composer require --dev orchestra/testbench` in your package directory. Testbench integrates seamlessly with Laravel’s autoloader and requires no additional configuration for basic usage. For advanced setups, define providers or aliases in your `testbench.yaml` or test classes.
Which Laravel versions does Testbench support, and how do I ensure compatibility?
Testbench aligns with Laravel’s release cycle: v11.x supports Laravel 10.x/11.x, v10.x for Laravel 9.x, etc. Check the [Testbench documentation](https://packages.tools/testbench) for version matrices. Use `orchestra/testbench-core` constraints in `composer.json` to lock versions and avoid conflicts.
Can I use Testbench with PestPHP instead of PHPUnit?
Yes, Testbench supports PestPHP natively. Ensure your `composer.json` includes Pest and configure Testbench’s `$__filename` resolution in Pest’s `pest.php`. Testbench’s traits (e.g., `WithFixtures`) work identically in both frameworks.
How do I mock Laravel’s service container or dependencies in tests?
Use Testbench’s `InteractsWithMockery` trait to mock services. Bind dependencies in `setUp()` with `$this->app->bind()` or mock them via Mockery’s `mock()` method. For complex setups, leverage Laravel’s container methods like `app()->instance()` or `app()->singleton()`.
What’s the best way to handle database fixtures in Testbench tests?
Use the `WithFixtures` trait to load fixtures before tests. Configure your database connection in `phpunit.xml` or `pest.php` and define fixtures in `database/fixtures/`. Flush the database between tests with `$this->artisan('migrate:fresh')` or Testbench’s `flushDatabase()` helper.
Are there performance considerations for running Testbench in CI/CD pipelines?
Testbench supports parallel test execution with `--parallel` in PHPUnit/Pest. Use SQLite for faster tests or PostgreSQL/MySQL for production-like environments. Avoid shared state between tests (e.g., fixtures) to prevent flaky results. Monitor CI runtime with tools like GitHub Actions’ `time` command.
How do I test package routes or HTTP endpoints with Testbench?
Use Laravel’s `Http::fake()` or `actingAs()` helpers to test routes. Register your package’s routes in `TestCase::setUp()` via `$this->app->register()` or manually in `routes/web.php`. Assert responses with PHPUnit’s `assertJson()` or Pest’s `assertResponse()` methods.
What alternatives exist to Testbench for Laravel package testing?
For lightweight testing, consider Laravel’s built-in `createApplication()` method or `laravel-shift/blueprint`. For advanced setups, `spatie/laravel-test-tools` offers utilities like fake factories. However, Testbench remains the most comprehensive solution for full Laravel integration, including providers, migrations, and fixtures.
How do I customize Testbench’s test skeleton or configuration?
Define a `testbench.yaml` file in your package root to configure providers, aliases, or environment variables. Override defaults in test classes via `setUp()` or use Testbench’s `createApplication()` method with custom parameters. For complex setups, extend the `TestCase` class.
What should I do if Testbench tests fail on Windows due to path/symlink issues?
Update to Testbench v10.8.0+ to resolve symlink handling bugs. Ensure your CI pipeline uses a consistent environment (e.g., GitHub Actions’ Windows runners with WSL). Test locally with Docker or a VM to replicate CI conditions. Avoid hardcoded paths in tests.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope