Skip to content

Commit 09f0bb5

Browse files
committed
Fix phpstan
1 parent fbd2f83 commit 09f0bb5

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/Browser/BrowserContext.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public function dispatchEvent(string $eventName, array $params): void
8585
if ('binding' === $eventName) {
8686
$bindingName = $params['name'];
8787
if (is_string($bindingName) && isset($this->bindings[$bindingName]) && is_callable($this->bindings[$bindingName])) {
88+
if (!is_string($params['pageId'])) {
89+
throw new ProtocolErrorException('Invalid pageId in binding event', 0);
90+
}
8891
$source = [
8992
'context' => $this,
9093
'page' => $this->pages[$params['pageId']] ?? null,

src/Transport/JsonRpc/JsonRpcTransport.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ private function handleEvent(array $event): void
272272
}
273273

274274
$objectId = $event['objectId'];
275+
if (!is_string($objectId)) {
276+
$this->logger->warning('Invalid objectId in event', ['event' => $event]);
277+
278+
return;
279+
}
280+
275281
if (isset($this->eventDispatchers[$objectId])) {
276282
$this->logger->debug('Dispatching event to registered handler', [
277283
'objectId' => $objectId,

tests/Integration/Browser/BrowserContextTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,17 @@ public function itSetsGeolocation(): void
133133

134134
$page->click('button');
135135

136-
usleep(500000);
136+
// Poll for either coordinates or error text since Page::waitForFunction is not available
137+
$deadline = microtime(true) + 5.0; // 5 seconds
138+
do {
139+
$content = $page->content() ?? '';
140+
$hasCoordinates = str_contains($content, '59.95,30.31667');
141+
$hasError = str_contains($content, 'Error');
142+
if ($hasCoordinates || $hasError) {
143+
break;
144+
}
145+
usleep(100 * 1000); // 100ms
146+
} while (microtime(true) < $deadline);
137147

138148
$content = $page->content();
139149
$hasCoordinates = str_contains($content, '59.95,30.31667');

tests/Integration/Locator/LocatorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ public function itTakesAScreenshotOfAnElement(): void
168168
$this->assertStringStartsWith(base64_decode('iVBORw0KGgo='), base64_decode($binary));
169169
}
170170

171+
#[Test]
172+
public function itEvaluatesElementTagNameAndCss(): void
173+
{
174+
$tagName = $this->page->locator('h1')->evaluate('element => element.tagName');
175+
$this->assertEquals('H1', $tagName);
176+
177+
$width = $this->page->locator('#div-1')->evaluate('element => window.getComputedStyle(element).width');
178+
$this->assertEquals('50px', $width);
179+
}
180+
171181
private static function findFreePort(): int
172182
{
173183
return 0;

0 commit comments

Comments
 (0)