Skip to content

Commit e7c2703

Browse files
committed
cs
1 parent 4b9fd40 commit e7c2703

21 files changed

Lines changed: 440 additions & 158 deletions

config/services.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Playwright\Symfony\Client\ResponseConverter;
2020
use Playwright\Symfony\Command\DebugPlaywrightCommand;
2121
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
22+
2223
use function Symfony\Component\DependencyInjection\Loader\Configurator\param;
2324
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
2425

src/Asset/AssetMapperProxy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Playwright\Symfony\Client\Interception\AssetLocatorInterface;
1919
use Symfony\Component\Mime\MimeTypes;
2020

21+
/**
22+
* @author Simon André <smn.andre@gmail.com>
23+
*/
2124
final class AssetMapperProxy implements AssetLocatorInterface
2225
{
2326
private ?object $mapper;

src/BrowserKit/PlaywrightClient.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use Playwright\Browser\BrowserContextInterface;
1818
use Playwright\Page\PageInterface;
19+
use Playwright\Symfony\Util\XPathHelper;
1920
use Symfony\Component\BrowserKit\AbstractBrowser;
2021
use Symfony\Component\BrowserKit\CookieJar;
2122
use Symfony\Component\BrowserKit\History;
@@ -33,6 +34,8 @@
3334
* - Builds a DomCrawler snapshot from the live DOM after each action.
3435
*
3536
* @extends AbstractBrowser<Request, BrowserKitResponse>
37+
*
38+
* @author Simon André <smn.andre@gmail.com>
3639
*/
3740
final class PlaywrightClient extends AbstractBrowser
3841
{
@@ -115,7 +118,7 @@ protected function doRequest($request): BrowserKitResponse
115118
*/
116119
public function click(Link $link, array $serverParameters = []): Crawler
117120
{
118-
$xpath = \Playwright\Symfony\Util\XPathHelper::buildXPath($link->getNode());
121+
$xpath = XPathHelper::buildXPath($link->getNode());
119122
$locator = $this->page->locator('xpath='.$xpath);
120123
$this->handlePotentialPopup(static function () use ($locator): void {
121124
$locator->click();
@@ -137,7 +140,7 @@ public function submit(Form $form, array $values = [], array $serverParameters =
137140
\Playwright\Symfony\Util\FormInteractor::fill($this->page, $form);
138141

139142
$this->handlePotentialPopup(function () use ($form): void {
140-
$xpath = \Playwright\Symfony\Util\XPathHelper::buildXPath($form->getNode());
143+
$xpath = XPathHelper::buildXPath($form->getNode());
141144
$this->page->locator('xpath='.$xpath)->evaluate('el => el.requestSubmit ? el.requestSubmit() : el.submit()');
142145
});
143146

src/Client/Interception/AssetLocatorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
/**
1818
* Describes a service able to resolve assets for a given request path.
19+
*
20+
* @author Simon André <smn.andre@gmail.com>
1921
*/
2022
interface AssetLocatorInterface
2123
{

src/Client/Interception/AssetServer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* but can aggregate any number of locators (filesystem, custom resolvers, etc.).
2222
*
2323
* @author Simon André <smn.andre@gmail.com>
24+
*
25+
* @internal
2426
*/
2527
final class AssetServer
2628
{

src/Client/PlaywrightClient.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
use Symfony\Component\BrowserKit\AbstractBrowser;
2424
use Symfony\Component\BrowserKit\Request as BrowserKitRequest;
2525
use Symfony\Component\BrowserKit\Response as BrowserKitResponse;
26-
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
27-
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
2826
use Symfony\Component\DomCrawler\Crawler;
2927
use Symfony\Component\DomCrawler\Form;
3028
use Symfony\Component\DomCrawler\Link;
29+
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
30+
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
3131
use Symfony\Component\HttpKernel\HttpKernelInterface;
3232
use Symfony\Component\HttpKernel\KernelInterface;
3333
use Symfony\Component\HttpKernel\Profiler\Profile;
@@ -181,7 +181,7 @@ public function getCrawler(): Crawler
181181
} catch (\Throwable $e) {
182182
if (str_contains($e->getMessage(), 'navigating')) {
183183
usleep(200000); // 200ms
184-
$retryCount++;
184+
++$retryCount;
185185
continue;
186186
}
187187
throw $e;
@@ -264,10 +264,10 @@ public function clearCookie(string $name, ?string $domain = null, string $path =
264264
// Behavior contract (used by tests): clearCookie removes the cookie.
265265
// We use clearCookies() with a filter if possible, or fallback to setting it to empty if API is limited.
266266
// Actually, Playwright PHP clearCookies() doesn't take arguments yet in some versions.
267-
267+
268268
// Better: use addCookies with a very old expiration date to force deletion if the API doesn't support selective clear.
269269
// But for our tests, setting it to empty AND returning null in getCookie is usually enough if handled consistently.
270-
270+
271271
$options = array_filter([
272272
'domain' => $domain,
273273
'path' => $path,
@@ -368,12 +368,12 @@ protected function doRequest(object $request): BrowserKitResponse
368368
$url = parse_url($uri);
369369
$path = ($url['path'] ?? '/').(isset($url['query']) ? '?'.$url['query'] : '');
370370

371-
if ($request->getMethod() === 'GET' && empty($request->getParameters())) {
371+
if ('GET' === $request->getMethod() && empty($request->getParameters())) {
372372
$this->visit($path);
373373
} else {
374374
// For POST or requests with parameters, we should ideally use a synthetic form
375375
// but for now, we'll just visit the path to trigger the interception.
376-
// If it's a POST, we might need a more complex implementation similar to
376+
// If it's a POST, we might need a more complex implementation similar to
377377
// the other PlaywrightClient.
378378
$this->visit($path);
379379
}

src/Client/RequestConverter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* Converts Playwright requests to Symfony requests.
2424
*
2525
* @author Simon André <smn.andre@gmail.com>
26+
*
27+
* @internal
2628
*/
2729
class RequestConverter
2830
{
@@ -48,7 +50,6 @@ public function convertToSymfonyRequest(RequestInterface $playwrightRequest): Sy
4850
'HTTPS' => ($url['scheme'] ?? 'http') === 'https' ? 'on' : 'off',
4951
];
5052

51-
// Normalize headers
5253
$lower = array_change_key_case($headers, CASE_LOWER);
5354
foreach ($headers as $name => $value) {
5455
$key = strtoupper(str_replace('-', '_', (string) $name));
@@ -59,20 +60,19 @@ public function convertToSymfonyRequest(RequestInterface $playwrightRequest): Sy
5960
}
6061
}
6162

62-
// Parse cookies
6363
if (isset($lower['cookie'])) {
6464
$cookies = $this->parseCookieHeader($lower['cookie']);
6565
}
6666

6767
$content = null;
6868
if ($postData) {
6969
$contentType = $lower['content-type'] ?? '';
70-
if (str_starts_with(strtolower((string) $contentType), 'application/x-www-form-urlencoded')) {
70+
if (str_starts_with(strtolower($contentType), 'application/x-www-form-urlencoded')) {
7171
parse_str($postData, $parameters);
7272
$content = $postData;
73-
} elseif (str_starts_with(strtolower((string) $contentType), 'multipart/form-data')) {
73+
} elseif (str_starts_with(strtolower($contentType), 'multipart/form-data')) {
7474
$content = $postData;
75-
$this->parseMultipartFormData((string) $contentType, $postData, $parameters, $files);
75+
$this->parseMultipartFormData($contentType, $postData, $parameters, $files);
7676
} else {
7777
$content = $postData;
7878
}

src/Client/ResponseConverter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
* like CSS/JS/images returned by AssetMapper and other responders.
2727
*
2828
* @author Simon André <smn.andre@gmail.com>
29+
*
30+
* @internal
2931
*/
3032
class ResponseConverter
3133
{
@@ -34,19 +36,16 @@ class ResponseConverter
3436
*/
3537
public function prepareFulfillOptions(SymfonyResponse $response): array
3638
{
37-
// Normalize and prepare headers
3839
$headers = $this->formatHeaders($response->headers->all());
3940
$contentType = $response->headers->get('content-type') ?: null;
4041

41-
// Compute body for all Response variants
4242
$body = $response->getContent();
4343

4444
// BinaryFileResponse does not expose content via getContent()
4545
if ((false === $body || '' === $body) && $response instanceof BinaryFileResponse) {
4646
$file = $response->getFile();
4747
$path = $file->getPathname();
4848
$body = @file_get_contents($path) ?: '';
49-
// Ensure we have a sane content type even if missing
5049
if (!$contentType) {
5150
$ext = pathinfo($path, PATHINFO_EXTENSION);
5251
$map = [

src/Command/DebugPlaywrightCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ private function checkNodeJs(): bool
133133

134134
private function executeWithTimeout(string $command, int $timeoutSeconds = 10): bool
135135
{
136-
// Use timeout command on Unix systems, or timeout via proc_open for better control
137136
if (PHP_OS_FAMILY === 'Windows') {
138137
$fullCommand = sprintf('timeout %d %s 2>nul', $timeoutSeconds, $command);
139138
} else {

src/DependencyInjection/PlaywrightExtension.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public function load(array $configs, ContainerBuilder $container): void
5454
$container->setParameter('playwright.asset_public_roots', $assetConfig['public_roots'] ?? ['%kernel.project_dir%/public']);
5555
$container->setParameter('playwright.asset_dev_no_cache', $assetConfig['disable_cache'] ?? true);
5656

57-
// Register Playwright browsers (default + named)
5857
$this->registerBrowsers($container, $config['browsers'] ?? [], $config['default_browser'] ?? 'default');
5958

6059
$container->register(BrowserKitClient::class, BrowserKitClient::class)
@@ -75,7 +74,6 @@ public function getAlias(): string
7574
*/
7675
private function registerBrowsers(ContainerBuilder $container, array $browsersConfig, string $defaultBrowser): void
7776
{
78-
// Ensure a default browser exists even if no config provided
7977
if (!isset($browsersConfig[$defaultBrowser])) {
8078
$browsersConfig[$defaultBrowser] = [];
8179
}
@@ -91,14 +89,12 @@ private function registerBrowsers(ContainerBuilder $container, array $browsersCo
9189
$browserConfig = $cfg;
9290
$serviceId = sprintf('playwright.browser.%s', $name);
9391

94-
// Build PlaywrightConfig definition from array config
9592
$configDef = new Definition(PlaywrightConfig::class);
9693
$configArgs = $this->mapBrowserConfigArgs($browserConfig);
9794
$configDef->setArguments($configArgs);
9895

9996
$container->setDefinition($serviceId.'.config', $configDef);
10097

101-
// Create BrowserContextInterface via factory
10298
$browserContextDef = new Definition(BrowserContextInterface::class);
10399
$browserContextDef->setFactory([self::class, 'createBrowserContext']);
104100
$browserType = $cfg['type'] ?? 'chromium';
@@ -110,11 +106,9 @@ private function registerBrowsers(ContainerBuilder $container, array $browsersCo
110106
$container->setDefinition($serviceId, $browserContextDef);
111107
$browserServiceIds[$name] = $serviceId;
112108

113-
// Autowire named arguments like BrowserContextInterface $firefoxDebug
114109
$this->registerAutowiredBrowserAlias($container, $name, $serviceId);
115110
}
116111

117-
// Default aliases similar to http_client
118112
if (isset($browserServiceIds[$defaultBrowser])) {
119113
$container->setAlias('playwright.browser', $browserServiceIds[$defaultBrowser])->setPublic(false);
120114
$container->setAlias(BrowserContextInterface::class, $browserServiceIds[$defaultBrowser])->setPublic(false);

0 commit comments

Comments
 (0)