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

Browser Laravel Package

zenstruck/browser

A Laravel-friendly browser testing toolkit built on Symfony BrowserKit and Panther. Easily crawl pages, click links, submit forms, assert on HTML, and drive real headless browsers—great for end-to-end tests and fluent, expressive UI assertions.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony-First Fit: The package is optimized for Symfony (KernelBrowser) and Panther (real browser testing), making it a natural fit for Laravel applications using Symfony components (e.g., HTTP Kernel, Panther for JS testing).
  • Fluent API Alignment: The fluent, chainable syntax aligns well with Laravel’s eloquent query builder and testing conventions, reducing cognitive load for developers familiar with Laravel’s testing patterns.
  • Dual Testing Modes: Supports fast Kernel-based tests (for API/non-JS routes) and Panther-based tests (for JS-heavy UIs), addressing Laravel’s need for both performance and realism in testing.

Integration Feasibility

  • Laravel Compatibility:
    • KernelBrowser: Works seamlessly with Laravel’s HTTP Kernel (via Symfony\Component\HttpKernel\HttpKernelInterface), requiring minimal setup (e.g., wrapping Laravel’s kernel in Symfony’s test client).
    • PantherBrowser: Requires Symfony Panther (symfony/panther), which Laravel can integrate via laravel/browser-kit-testing or standalone.
    • PHPUnit Extension: The BrowserExtension provides automatic test artifact capture (screenshots, source), which is valuable for Laravel’s debugging workflows.
  • Laravel-Specific Adjustments:
    • May need a custom test case base class to bridge Laravel’s HttpTestCase with Symfony’s KernelTestCase.
    • Authentication: Laravel’s actingAs() can be mapped to Symfony’s actingAs() via a wrapper trait.
    • Route Generation: Laravel’s route() helper may need adaptation for Symfony’s router (e.g., UrlGeneratorInterface).

Technical Risk

Risk Area Mitigation Strategy
Symfony Dependency Use Symfony’s HTTP Kernel via Laravel’s app() container or a wrapper service.
Panther Overhead Reserve Panther tests for critical JS paths; use KernelBrowser for API/non-JS.
Route/URL Conflicts Standardize on Symfony’s router for consistency or create a Laravel-Symfony adapter.
Test Isolation Leverage disableReboot()/enableReboot() to control Laravel’s service container state.
Artifact Storage Configure BROWSER_SOURCE_DIR to point to Laravel’s storage/logs/browser/ or similar.

Key Questions

  1. Symfony Kernel Integration:
    • How will Laravel’s HTTP Kernel be exposed to Symfony’s test client? (e.g., via a custom TestKernel or service provider).
    • Can Laravel’s route caching interfere with Symfony’s router? If so, how will routes be resolved dynamically?
  2. Authentication:
    • How will Laravel’s Auth::login() or actingAs() integrate with Symfony’s actingAs()? Will a trait or service bridge the gap?
  3. Panther Setup:
    • Will Laravel’s queue workers or event listeners interfere with Panther’s headless browser? If so, how will they be mocked?
  4. Performance:
    • What’s the baseline overhead of KernelBrowser vs. Laravel’s native HttpTestCase? Will it justify the switch?
  5. Debugging:
    • How will Laravel’s exception handlers (e.g., App\Exceptions\Handler) interact with Symfony’s error handling in tests?
  6. CI/CD Impact:
    • Will Panther tests slow down CI pipelines? If so, will they be gated to specific branches or parallelized?

Integration Approach

Stack Fit

  • Core Stack:
    • Laravel 10+ (Symfony 6+ compatible).
    • PHPUnit 9+ (for extension support).
    • Symfony Panther (symfony/panther) for JS testing.
    • Zenstruck Foundry (optional, for test data factories).
  • Alternatives:
    • For non-JS routes, prioritize KernelBrowser (faster, no browser dependencies).
    • For JS-heavy apps, use PantherBrowser but isolate to critical paths.
  • Laravel-Specific Tools:
    • PestPHP: If using Pest, create a custom BrowserTestCase to integrate with Zenstruck’s traits.
    • Laravel Dusk: If migrating from Dusk, assess whether Zenstruck’s PantherBrowser offers better maintainability.

Migration Path

  1. Phase 1: KernelBrowser Adoption
    • Replace Laravel’s HttpTestCase with a custom test case extending Symfony\Bundle\FrameworkBundle\Test\KernelTestCase.
    • Example:
      use Zenstruck\Browser\Test\HasBrowser;
      use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
      
      class BrowserTestCase extends KernelTestCase
      {
          use HasBrowser;
      }
      
    • Migrate API tests to use KernelBrowser (e.g., ->get('/api/endpoint')->assertJson()).
  2. Phase 2: PantherBrowser for JS
    • Add symfony/panther and mtdowling/jmespath.php to composer.json.
    • Create a Panther test case:
      use Zenstruck\Browser\Test\HasBrowser;
      use Symfony\Component\Panther\PantherTestCase;
      
      class PantherTestCase extends PantherTestCase
      {
          use HasBrowser;
      }
      
    • Migrate Dusk tests to use PantherBrowser (e.g., ->click('button')->assertSeeIn()).
  3. Phase 3: Fluent API Adoption
    • Replace assertions (e.g., assertResponseOk()) with Zenstruck’s fluent syntax:
      // Before (Laravel)
      $response = $this->get('/posts');
      $response->assertOk();
      
      // After (Zenstruck)
      $this->browser()->get('/posts')->assertSuccessful();
      
    • Use use() blocks for complex interactions (e.g., mocking services).

Compatibility

Component Compatibility Notes
Laravel Routes KernelBrowser uses Symfony’s router; ensure route names are consistent.
Middleware Laravel middleware (e.g., ShareErrorsFromSession) must be kernel-aware.
Authentication Laravel’s Auth facade may need a Symfony adapter (e.g., UserProviderInterface).
Blade Templates KernelBrowser renders Blade via Symfony’s templating; no changes needed.
API Resources Use assertJsonMatches() for JSON:API or GraphQL assertions.
File Uploads PantherBrowser supports attachFile(); KernelBrowser requires multipart/form-data.

Sequencing

  1. Start with KernelBrowser for API and non-JS routes (lowest risk).
  2. Add PantherBrowser only for JS-critical paths (higher CI cost).
  3. Gradually replace assertions with Zenstruck’s fluent syntax.
  4. Enable the PHPUnit extension last to capture test artifacts (debugging aid).
  5. Optimize performance by:
    • Disabling reboot() for stateless tests.
    • Using interceptRedirects() for form submissions.

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Fluent API eliminates repetitive assert calls.
    • Centralized Debugging: PHPUnit extension auto-saves screenshots/source on failures.
    • Consistent Syntax: Aligns with Symfony’s testing patterns (easier for multi-framework teams).
  • Cons:
    • Symfony Dependency: Adds abstraction layer between Laravel and Symfony.
    • Panther Maintenance: Requires headless browser drivers (e.g., ChromeDriver) in CI/CD.
    • Route Management: Must ensure Symfony router and Laravel routes stay in sync.

Support

  • Learning Curve:
    • Low for Laravel devs: Fluent syntax is intuitive; similar to Laravel’s query builder.
    • Moderate for Symfony: Requires familiarity with Symfony’s KernelTestCase and PantherTestCase.
  • Documentation Gaps:
    • Laravel-Specific Guides: Missing docs on bridging Laravel’s Auth or route generation.
    • Troubleshooting: Limited examples for Panther + Laravel event listeners.
  • Community:
    • Zenstruck’s GitHub: Active issues/PRs; Symfony-centric but responsive.
    • Laravel Forums: Limited adoption; may need internal runbooks.

Scaling

  • Test Parallelization:
    • **
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui