symfony/browser-kit
Symfony BrowserKit simulates a web browser in PHP for testing and automation: make requests, follow links, click buttons, and submit forms programmatically. Includes an implementation powered by Symfony HttpClient for real HTTP requests.
Pros:
Client + Crawler without full Symfony).Cons:
DomCrawler). For SPAs or dynamic JS-rendered content, pair with Symfony Panther or Puppeteer.use Symfony\Component\BrowserKit\HttpBrowser;
use Symfony\Component\DomCrawler\Crawler;
$client = new HttpBrowser();
$client->request('GET', '/checkout');
$form = $client->selectButton('Submit Order')->form();
$crawler = $client->submit($form);
$crawler->filter('h1')->text() === 'Order Confirmed';
$client = new HttpBrowser();
$client->request('GET', 'https://example.com/products');
$products = $client->filter('.product')->each(fn(Crawler $node) => [
'name' => $node->filter('h2')->text(),
'price' => $node->filter('.price')->text(),
]);
phpunit.xml for pre-deploy validation:
<listeners>
<listener class="App\Tests\BrowserKitListener" />
</listeners>
RefreshDatabase trait for isolated test environments.| Risk Area | Mitigation Strategy |
|---|---|
| JavaScript Dependency | Use Symfony Panther for JS-heavy workflows or accept limitations for server-side HTML. |
| Laravel-Specific Quirks | Test with Laravel’s Testing facade or wrap BrowserKit in a custom service. |
| Performance Overhead | Benchmark against Guzzle-only requests for critical paths. |
| Maintenance Burden | Leverage Symfony’s active maintenance (last release: 2026-05-29). |
| State Management | Use Laravel Sessions or custom cookie handlers for complex auth flows. |
DomCrawler for scraping vs. History for testing).Core Laravel Integration Points:
Http::get() calls with BrowserKit::request() for context-aware scraping (e.g., cookies, headers).use Symfony\Component\BrowserKit\TestCase;
class CheckoutTest extends TestCase {
public function testOrderFlow() {
$client = static::createClient();
$client->request('GET', '/cart');
// ... assertions
}
}
use Symfony\Component\BrowserKit\HttpBrowser;
class ScrapeJob implements ShouldQueue {
public function handle() {
$client = new HttpBrowser();
$client->request('GET', 'https://target-site.com');
// Process data...
}
}
Symfony Ecosystem:
HttpClient, so existing HTTP client configurations (proxies, auth) apply.| Phase | Action Items | Tools/Libraries |
|---|---|---|
| Assessment | Audit manual testing workflows and scraping scripts for BrowserKit compatibility. | Postman (for API vs. HTML analysis) |
| Pilot | Replace 1–2 critical test suites (e.g., checkout, auth) with BrowserKit. | PHPUnit, PestPHP |
| Core Integration | Add BrowserKit to CI/CD pipeline (e.g., GitHub Actions, Laravel Forge). | GitHub Actions, Envoyer |
| Scaling | Implement queued scraping for high-volume tasks. | Laravel Queues, Redis |
| Optimization | Profile performance; cache responses for static content. | Symfony Cache, Laravel Cache |
| Maintenance | Set up automated dependency updates (e.g., symfony/browser-kit:^8.0). |
GitHub Dependabot, Renovate |
symfony/http-client.Phase 1: Testing Replacement (4–6 weeks)
Phase 2: Scraping Implementation (3–
How can I help you explore Laravel packages today?