- How do I install Laravel TestBench for Laravel 12 or 13?
- Run `composer require --dev graham-campbell/testbench` in your project. No additional configuration is needed—just extend `AbstractPackageTestCase` or `AbstractAppTestCase` in your test classes. Ensure your `phpunit.xml` config matches PHPUnit 9–11 (TestBench drops PHPUnit 12 support due to instability).
- Can I use TestBench for testing a standalone Laravel package without a full app?
- Yes, TestBench is designed for this exact use case. Extend `AbstractPackageTestCase` in your package tests, and it will handle bootstrapping Laravel’s core services in isolation. This avoids requiring a full Laravel installation for package-level testing.
- What’s the difference between `AbstractPackageTestCase` and `AbstractAppTestCase`?
- `AbstractPackageTestCase` is optimized for testing Laravel packages in isolation (e.g., service providers, models, or standalone components). `AbstractAppTestCase` is for application-level tests where you need a full Laravel environment. Choose based on whether you’re testing a package or an app.
- Does TestBench support Laravel’s built-in testing tools like `php artisan test`?
- No, TestBench relies on Orchestral Testbench (a fork of Laravel’s legacy test tools) and doesn’t integrate with Laravel’s native `php artisan test` or PEST. If you’re using PEST or Laravel’s built-in tools, TestBench may add unnecessary complexity.
- Why does TestBench exclude PHPUnit 12 support? Is it stable?
- TestBench explicitly drops PHPUnit 12 due to reported instability across minor releases. The maintainer recommends sticking with PHPUnit 11 for consistency. If PHPUnit 12 stabilizes, monitor updates or consider migrating to Laravel’s native testing tools.
- How do I mock services in TestBench? Does it use Mockery or PHPUnit’s native mocks?
- TestBench uses Mockery for mocking, which is deprecated in PHPUnit 11+. If you’re invested in Mockery’s syntax, TestBench is a good fit. For new projects, consider PHPUnit’s native mocks or plan a migration path away from Mockery.
- Will TestBench work with CI/CD pipelines like GitHub Actions or parallel test execution?
- Yes, TestBench integrates seamlessly with CI/CD. It supports parallel test execution out of the box. However, avoid using `kylekatarnls/update-helper` in your CI, as TestBench explicitly blocks it to prevent conflicts with its test environment setup.
- What if I’m using Laravel 8 or 9? Are there breaking changes from older versions?
- TestBench supports Laravel 8–13, but versions 6.0+ introduced static methods like `getBasePath()` and `getRequiredServiceProviders()`. If you’re upgrading from an older version, audit your test suite for dynamic calls to these methods and update them to static calls.
- Is TestBench a good choice if I’m migrating from Laravel’s legacy test tools?
- Yes, TestBench is built on Orchestral Testbench (a fork of Laravel’s legacy tools), so it’s a natural upgrade path. However, if you’re modernizing your stack, evaluate Laravel’s native testing tools or PEST, as they may offer better long-term support.
- How do I test database interactions in TestBench? Does it support migrations or factories?
- TestBench integrates with Laravel’s database testing utilities. Use `createApplication()` to bootstrap the app, then leverage Laravel’s `DatabaseMigrations` or `DatabaseTransactions` traits for migrations and factories. Example: `use CreatesApplication;` in your test class.