- Can I use lib-innerbrowser for Laravel API testing without Codeception?
- No, lib-innerbrowser is a core dependency for Codeception’s PhpBrowser module. For pure API testing in Laravel, use Laravel’s built-in `Http::fake()` or Pest’s HTTP tests instead. InnerBrowser is optimized for DOM/Blade validation, not stateless API workflows.
- How do I integrate lib-innerbrowser with Laravel’s built-in testing helpers (e.g., `actingAs()`)?
- Use the `codeception/module-laravel` package, which bridges Codeception’s `$I` helpers with Laravel’s auth system. Example: `$I->amLoggedInAs($user)` mimics `actingAs()` but includes session cookie management for subsequent requests.
- Will lib-innerbrowser work with Laravel Sanctum or Passport for API token auth?
- Yes, but you’ll need to manually set the `Authorization` header in your Codeception test. Use `$I->sendGET('/api/endpoint', ['Authorization' => 'Bearer ' . $token])` or extend the Laravel module to auto-inject tokens via `actingAs()`.
- What’s the performance difference between lib-innerbrowser and Laravel’s `TestResponse` assertions?
- InnerBrowser adds ~10–20ms per request due to DOM parsing, while `TestResponse` assertions are near-instant. Use `TestResponse` for API tests and reserve InnerBrowser for UI-heavy workflows like form submissions or Blade template validation.
- Can I test JavaScript-rendered content (e.g., Alpine.js) with lib-innerbrowser?
- No, lib-innerbrowser is a headless HTTP client and cannot execute JavaScript. For dynamic content, use Laravel Dusk or Playwright. InnerBrowser is ideal for server-rendered Blade templates or static DOM assertions.
- How do I mock database interactions in tests using lib-innerbrowser?
- Combine InnerBrowser with Laravel’s `DatabaseMigrations` or `DatabaseTransactions` traits. Example: `$I->seeInDatabase('posts', ['title' => 'Test'])` after submitting a form. The `codeception/module-laravel` package provides this helper.
- What Laravel versions and PHPUnit does lib-innerbrowser support?
- Lib-innerbrowser works with Laravel 10+ (Symfony 7/8) and PHPUnit 10–13. It has no direct Laravel dependencies but relies on Symfony’s `DomCrawler`. Ensure your `composer.json` aligns with these constraints to avoid conflicts.
- How do I debug failing tests with lib-innerbrowser?
- Enable debug mode in your `codeception.yml` with `debug: true`. Use `$I->domDump()` to inspect the parsed DOM, or leverage Codeception’s built-in `retry()` helper for flaky tests. Check the `AcceptanceTester` logs for request/response details.
- Is there a way to parallelize tests using lib-innerbrowser?
- Yes, install the `codeception/parallel` module and configure it in your `codeception.yml`. InnerBrowser tests can run in parallel, but avoid shared state (e.g., global sessions) to prevent race conditions. Aim for stateless workflows per test.
- What are the alternatives to lib-innerbrowser for Laravel functional testing?
- For lightweight HTTP tests, use Laravel’s `TestResponse` assertions or Pest’s HTTP tests. For browser automation, use Dusk (Legacy) or Playwright. InnerBrowser is unique in offering DOM inspection without a real browser, making it ideal for Blade/CSRF/form validation.