- 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.