orchestra/testbench-browser-kit
Adds Laravel BrowserKit testing to Orchestra Testbench for package development. Swap your base test case to Orchestra\Testbench\BrowserKit\TestCase to use fluent visit/see/form APIs in functional tests across supported Laravel versions.
browser-kit-testing with Testbench compatibility, making it a natural fit for package developers who need to test UI/UX flows, forms, and API interactions in isolation. It aligns with Laravel’s testing ecosystem and avoids reinventing the wheel.TestCase) and browser-level testing (e.g., BrowserKit). This is critical for packages that interact with user-facing logic, authentication, or session state.visit(), click(), see(), etc.) mirror Laravel’s existing testing patterns, reducing cognitive load for developers familiar with the framework.Orchestra\Testbench\TestCase with Orchestra\Testbench\BrowserKit\TestCase—a minimal change requiring no additional configuration beyond Testbench itself.orchestra/testbench (v4+) and laravel/browser-kit-testing (v6+), both of which are actively maintained. Compatibility table covers Laravel 6–12, ensuring broad adoption.BrowserKit suffices)?actingAs, withSession) are valuable.attach(), type(), etc., methods are tailored for this.BrowserKit? If not, tests may fail silently or require additional setup.BrowserKit functionality is missing (e.g., testing redirects, CSRF-protected forms).HttpTests or XmlHttpTestCase instead).BrowserKit in application-level testing.orchestra/testbench (≥v4) and laravel/browser-kit-testing (≥v6) are installed.use Orchestra\Testbench\TestCase; with use Orchestra\Testbench\BrowserKit\TestCase;.TestCase class (as shown in the README) to centralize baseUrl and shared setup.TestCase classes to the new base class.BrowserKit tests from legacy unit tests.withoutMiddleware() with BrowserKit assertions.BrowserKit methods (e.g., visitRoute(), seeJsonStructure()) plus Testbench-specific helpers (e.g., actingAs()).BrowserKit is HTML-agnostic; for JS-heavy apps, pair with tools like Laravel Dusk or Pest’s browser testing.composer.json or .github/workflows.TestCase and write basic visit()/see() tests for core routes.type(), press(), attach()) for package-specific UI logic.actingAs(), withSession()) for stateful packages.seeJsonEquals(), seeJsonStructure()) if the package exposes endpoints.Client instantiation or Http facade usage for browser tests.see(), assertRedirectedTo()) reduce flakiness from ad-hoc assertions.BrowserKit and Testbench to the test stack, increasing build times and CI complexity.BrowserKit tests may fail due to:
dd($this->response->getContent()) to inspect raw responses during debugging.TESTING.md with:
BrowserKit tests are slower than unit tests (HTTP overhead). Optimize by:
--parallel).@skip-browser tags).--process-isolation in PHPUnit to avoid leaks.BrowserKit tests to critical paths. For example:
HttpTests for APIs).| Failure Type | Root Cause | Mitigation |
|---|---|---|
| Flaky Tests | Dynamic content (e.g., timestamps) | Use see() with static text or unique data (e.g., see('User ID: ' . $user->id)). |
| Missing Dependencies | ChromeDriver not installed in CI | Add a CI step to install drivers (e.g., apt-get install -y chromium-driver). |
| Session Leaks | Tests polluting shared state | Use refreshApplication() or withoutMiddleware() to isolate tests. |
| Selector Changes | Package updates break CSS selectors | Prefer name/id attributes over classes in click()/type(). |
| Timeouts | Slow package responses | Increase timeout in BrowserKit config or optimize package performance. |
BrowserKit methods (e.g., visit() → click() → see()).How can I help you explore Laravel packages today?