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

graham-campbell/testbench

Laravel TestBench adds testing helpers for Laravel packages and apps, built on PHPUnit, Mockery, and Orchestral Testbench. Supports Laravel 8–13 and PHP 7.4–8.5, providing a solid base for fast, reliable package tests.

View on GitHub
Deep Wiki
Context7

Providing some testing functionality for Laravel

Frequently asked questions about Testbench
How do I install Laravel TestBench for Laravel 13?
Run `composer require --dev graham-campbell/testbench` in your project. TestBench supports Laravel 13 out of the box with zero additional configuration. Ensure your `phpunit.xml` includes the TestBench autoloader if not using Laravel’s built-in PHPUnit setup.
Can I use TestBench for API testing in Laravel?
TestBench focuses on unit/integration testing (e.g., service providers, middleware) rather than full API testing. For API endpoints, pair it with Laravel’s HTTP tests or tools like PestPHP. TestBench provides a clean Laravel container for isolated assertions but lacks built-in API helpers.
What’s the difference between TestBench and Laravel’s built-in testing helpers?
TestBench extends Laravel’s native testing with abstract base classes (e.g., `AbstractTestCase`) for package-specific tests, while Laravel’s helpers are designed for application-level tests. TestBench is ideal for testing packages in isolation, whereas Laravel’s tools are better for app-wide integration scenarios.
Does TestBench support database testing or transactions?
TestBench itself doesn’t include database transaction utilities, but you can combine it with Laravel’s `RefreshDatabase` trait or PestPHP’s database testing features. The package prioritizes lightweight, isolated testing—database interactions should be handled by Laravel’s built-in tools.
How do I migrate from TestBench v5.x to v6.0 due to static method changes?
Update `getBasePath()` and `getRequiredServiceProviders()` to static calls (e.g., `AbstractTestCase::getBasePath()`). Review the [changelog](https://github.com/GrahamCampbell/Laravel-TestBench/blob/master/CHANGELOG.md) for v6.0 and run `composer update` after updating your test classes. Most breaking changes are documented clearly.
Will TestBench work with PHPUnit 12 despite the volatility warning?
TestBench explicitly excludes PHPUnit 12 due to instability across minor releases. Stick to PHPUnit 9–11 for reliability. If you must use PHPUnit 12, monitor its updates closely or consider alternatives like PestPHP, which may handle newer PHPUnit versions better.
Can I use TestBench for testing Laravel Livewire components?
TestBench isn’t designed for Livewire-specific testing, but you can test Livewire logic (e.g., service providers, actions) within its isolated Laravel container. For component-level testing, use Livewire’s built-in testing tools or Dusk. TestBench excels at backend logic, not frontend interactions.
How does TestBench handle service provider registration in tests?
TestBench abstracts service provider registration via `getRequiredServiceProviders()` in your test classes. Override this method to specify providers needed for your tests. The package bootstraps a fresh Laravel container per test, ensuring clean isolation without global state pollution.
Are there performance concerns with booting Laravel containers in CI?
TestBench is optimized for speed, but booting Laravel containers in CI can add overhead. Use Laravel’s `--parallel` PHPUnit flag or cache dependencies (e.g., `composer install --optimize-autoloader`) to mitigate this. For large test suites, consider splitting tests into smaller suites.
What alternatives exist if TestBench doesn’t fit my needs?
For Laravel testing, consider PestPHP (a modern testing framework), Laravel Dusk (E2E browser testing), or Orchestral Testbench (if you need deeper Laravel integration without TestBench’s abstractions). If you need database-heavy testing, Laravel’s `RefreshDatabase` trait or factories may suffice without TestBench.
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle