PlaywrightKernelClient
Playwright\Symfony\Client\PlaywrightKernelClient
BrowserKit client that intercepts browser requests and routes them through Symfony's HttpKernel.
This is the core client for in-process E2E testing of Symfony applications. It combines a real
Playwright browser with Symfony's HttpKernel to enable full browser testing while maintaining
access to Symfony internals (services, events, profiler, request/response inspection).
Primary role in architecture:
- Returned by PlaywrightTestCase client factories
- Intercepts HTTP requests from the browser to configured hosts (localhost, 127.0.0.1)
- Routes intercepted requests through Symfony's kernel in the same PHP process
- Provides access to last Symfony request/response for assertions
- Integrates AssetServer for fast static asset serving (bypasses kernel)
How request interception works:
1. User calls visit('/path') → navigates browser to http://localhost/path
2. Browser makes HTTP request → intercepted via BrowserSessionInterface->setupRouting()
3. Request matched against interceptedHosts → if matched, proceeds to step 4
4. AssetServer checks if request is for static asset → if yes, serves directly
5. Otherwise: RequestConverter → HttpKernel->handle() → Kernel->terminate() → ResponseConverter → browser
6. Test can inspect via getLastSymfonyRequest(), getLastSymfonyResponse()
Key features:
- In-process kernel execution (no real HTTP, no separate server)
- Full access to Symfony container, services, and profiler
- beforeRequest() and afterResponse() hooks for custom logic
- Cookie management and authentication helpers
- BrowserKit API compatibility (visit, click, submit, getCrawler)
When to use:
- Testing your Symfony application with real browser behavior
- Need to inspect Symfony internals (request, response, services)
- Want fast E2E tests without network overhead
When NOT to use:
- Testing external websites → use BrowserKit\PlaywrightClient instead
- Need real HTTP networking behavior → use BrowserKit\PlaywrightClient instead
Methods
__construct()
Creates a client that routes browser requests through a Symfony kernel.
function __construct( BrowserSessionInterface $browser, private readonly HttpKernelInterface $kernel, private readonly RequestConverter $requestConverter, private readonly ResponseConverter $responseConverter, array $server = [], ?array $interceptedHosts = null, ?object $hookReceiver = null, ?AssetServer $assetServer = null, private readonly string $baseUrl = 'http://localhost', private ?LoggerInterface $logger = null, private readonly bool $debugLogging = false, )
catchExceptions()
voidControls whether exceptions thrown by the kernel are converted to responses.
function catchExceptions(bool $catchExceptions): void
visit()
PageInterfaceNavigates the browser page to a path relative to the configured base URL.
function visit(string $path): PageInterface
followRedirect()
CrawlerNavigates to the target of the redirect the browser was stopped on.
function followRedirect(): Crawler
getPage()
?PageInterfaceReturns the client's Playwright page, or null after its session is closed.
function getPage(): ?PageInterface
context()
?BrowserContextInterfaceReturns the client's isolated browser context, or null after its session is closed.
function context(): ?BrowserContextInterface
click()
CrawlerClicks a BrowserKit link in the live page and returns its updated crawler.
function click(Link $link, array $serverParameters = []): Crawler
submit()
CrawlerFills and submits a BrowserKit form in the live page.
function submit(Form $form, array $values = [], array $serverParameters = []): Crawler
getCrawler()
CrawlerReturns a crawler built from the live page content.
function getCrawler(): Crawler
setCookie()
voidAdds or replaces a cookie in both Playwright and BrowserKit.
function setCookie(string $name, string $value, array $options = []): void
getCookie()
?stringReturns a browser cookie value for the given URL.
function getCookie(string $name, ?string $url = null): ?string
clearCookies()
voidClears every cookie from Playwright and BrowserKit.
function clearCookies(): void
clearCookie()
voidRemoves a cookie from Playwright and BrowserKit.
function clearCookie(string $name, ?string $domain = null, string $path = '/'): void
authenticate()
voidSets the legacy AUTH cookie used by the package's simple authentication helper.
function authenticate(string $identifier = 'user', array $context = []): void
loginUser()
staticStores a Symfony security token and synchronizes its session cookie to Playwright.
function loginUser(object $user, string $firewallContext = 'main', array $tokenAttributes = []): static
logout()
staticClears the selected Symfony firewall token and its browser session cookie.
function logout(string $firewallContext = 'main'): static
getSession()
?SessionInterfaceReturns the Symfony session associated with the browser's session cookie.
function getSession(): ?SessionInterface
getLastSymfonyRequest()
?SymfonyRequestReturns the last Symfony request handled through browser interception.
function getLastSymfonyRequest(): ?SymfonyRequest
getRequest()
objectReturns the intercepted Symfony request when available, otherwise the BrowserKit request.
function getRequest(): object
getLastSymfonyResponse()
?SymfonyResponseReturns the last Symfony response handled through browser interception.
function getLastSymfonyResponse(): ?SymfonyResponse
getContainer()
?ContainerInterfaceReturns the kernel's test container when available, exposing private test services. Returns null when the configured HttpKernelInterface does not implement KernelInterface.
function getContainer(): ?ContainerInterface
enableProfiler()
voidEnable the profiler for the next request, mirroring KernelBrowser::enableProfiler().
function enableProfiler(): void
getResponse()
objectReturns the intercepted Symfony response when available, otherwise the BrowserKit response.
function getResponse(): object
getProfile()
?ProfileReturns the profile collected for the last profiled request.
function getProfile(): ?Profile
getBaseUrl()
stringReturns the base URL used to resolve relative navigation paths.
function getBaseUrl(): string
setInterceptedHosts()
voidReplaces the host names whose requests are routed through the Symfony kernel.
function setInterceptedHosts(array $hosts): void
getInterceptedHosts()
arrayReturns the host names whose requests are routed through the Symfony kernel.
function getInterceptedHosts(): array