Skip to content

Commit 8bee0da

Browse files
authored
Upgrade phpstan; increase phpstan level; fix a few bugs (#55)
1 parent f62470d commit 8bee0da

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
},
2121
"require-dev": {
2222
"mink/driver-testsuite": "dev-master",
23-
"phpstan/phpstan": "^1.10",
24-
"phpstan/phpstan-phpunit": "^1.3",
23+
"phpstan/phpstan": "^2",
24+
"phpstan/phpstan-phpunit": "^2",
2525
"phpunit/phpunit": "^9.6.8",
2626
"symfony/error-handler": "^5.4 || ^6.0 || ^7.0",
2727
"symfony/process": "^5.4 || ^6.0 || ^7.0",

phpstan.dist.neon

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ includes:
33
- vendor/phpstan/phpstan-phpunit/rules.neon
44

55
parameters:
6-
level: 9
6+
level: 10
77
paths:
88
- src
99
- tests
@@ -26,3 +26,13 @@ parameters:
2626
identifier: argument.type
2727
count: 1
2828
path: src/WebdriverClassicDriver.php
29+
-
30+
message: '#^Method Mink\\WebdriverClassicDriver\\WebdriverClassicDriver\:\:getWindowHandleFromName\(\) should return string but returns mixed\.$#'
31+
identifier: return.type
32+
count: 1
33+
path: src/WebdriverClassicDriver.php
34+
-
35+
message: '#^Parameter \#1 \$handle of method Facebook\\WebDriver\\Remote\\RemoteTargetLocator\:\:window\(\) expects string, mixed given\.$#'
36+
identifier: argument.type
37+
count: 3
38+
path: src/WebdriverClassicDriver.php

src/WebdriverClassicDriver.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,6 @@ public function executeScript(
670670
$this->getWebDriver()->executeScript($script);
671671
}
672672

673-
/**
674-
* {@inheritdoc}
675-
* @return mixed
676-
*/
677673
public function evaluateScript(
678674
#[Language('JavaScript')]
679675
string $script
@@ -971,7 +967,7 @@ private function executeJsOnXpath(
971967
* @throws DriverException
972968
*/
973969
private function executeJsOnElement(
974-
RemoteWebElement $element,
970+
WebDriverElement $element,
975971
#[Language('JavaScript')]
976972
string $script
977973
) {
@@ -1044,7 +1040,7 @@ private function getWindowHandleFromName(string $name): string
10441040
}
10451041
}
10461042

1047-
private function clickOnElement(RemoteWebElement $element): void
1043+
private function clickOnElement(WebDriverElement $element): void
10481044
{
10491045
$element->getLocationOnScreenOnceScrolledIntoView();
10501046
$element->click();
@@ -1108,14 +1104,11 @@ private function withWindow(?string $name, callable $callback): void
11081104
*/
11091105
private function findElement(
11101106
#[Language('XPath')]
1111-
string $xpath,
1112-
?RemoteWebElement $parent = null
1107+
string $xpath
11131108
): RemoteWebElement {
11141109
try {
11151110
$finder = WebDriverBy::xpath($xpath);
1116-
return $parent
1117-
? $parent->findElement($finder)
1118-
: $this->getWebDriver()->findElement($finder);
1111+
return $this->getWebDriver()->findElement($finder);
11191112
} catch (\Throwable $e) {
11201113
throw new DriverException("Failed to find element: {$e->getMessage()}", 0, $e);
11211114
}
@@ -1124,7 +1117,7 @@ private function findElement(
11241117
/**
11251118
* @throws DriverException
11261119
*/
1127-
private function selectRadioValue(RemoteWebElement $element, string $value): void
1120+
private function selectRadioValue(WebDriverElement $element, string $value): void
11281121
{
11291122
try {
11301123
(new WebDriverRadios($element))->selectByValue($value);
@@ -1142,7 +1135,7 @@ private function selectRadioValue(RemoteWebElement $element, string $value): voi
11421135
/**
11431136
* @throws DriverException
11441137
*/
1145-
private function selectOptionOnElement(RemoteWebElement $element, string $value, bool $multiple = false): void
1138+
private function selectOptionOnElement(WebDriverElement $element, string $value, bool $multiple = false): void
11461139
{
11471140
try {
11481141
$select = new WebDriverSelect($element);
@@ -1172,7 +1165,7 @@ private function selectOptionOnElement(RemoteWebElement $element, string $value,
11721165
*
11731166
* @throws DriverException
11741167
*/
1175-
private function deselectAllOptions(RemoteWebElement $element): void
1168+
private function deselectAllOptions(WebDriverElement $element): void
11761169
{
11771170
try {
11781171
(new WebDriverSelect($element))->deselectAll();
@@ -1190,7 +1183,7 @@ private function deselectAllOptions(RemoteWebElement $element): void
11901183
* @throws DriverException
11911184
*/
11921185
private function ensureInputType(
1193-
RemoteWebElement $element,
1186+
WebDriverElement $element,
11941187
#[Language('XPath')]
11951188
string $xpath,
11961189
string $type,
@@ -1233,7 +1226,7 @@ private function jsonEncode($value, string $action, string $field): string
12331226
* @param mixed $value
12341227
* @throws DriverException
12351228
*/
1236-
private function setElementDomProperty(RemoteWebElement $element, string $property, $value): void
1229+
private function setElementDomProperty(WebDriverElement $element, string $property, $value): void
12371230
{
12381231
$this->executeJsOnElement(
12391232
$element,

tests/WebdriverClassicConfig.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public static function getInstance(): self
2121

2222
public function createDriver(): WebdriverClassicDriver
2323
{
24-
$seleniumHost = $_SERVER['DRIVER_URL'];
24+
$seleniumHost = $_SERVER['DRIVER_URL'] ?? null;
25+
if (!is_string($seleniumHost)) {
26+
throw new \RuntimeException('Selenium host must be specified (as a string) in $_SERVER[DRIVER_URL].');
27+
}
2528

2629
return new WebdriverClassicDriver($this->getBrowserName(), [], $seleniumHost);
2730
}

tests/bootstrap.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
use Symfony\Component\Process\Process;
66

7-
$minkTestServerPort = isset($_SERVER['WEB_FIXTURES_HOST'])
8-
? parse_url($_SERVER['WEB_FIXTURES_HOST'], PHP_URL_PORT)
9-
: '8002';
7+
$fixturesHost = $_SERVER['WEB_FIXTURES_HOST'] ?? '';
8+
$minkTestServerPort = parse_url(is_string($fixturesHost) ? $fixturesHost : '', PHP_URL_PORT) ?: '8002';
109

1110
$minkTestServer = new Process([
1211
PHP_BINARY,

0 commit comments

Comments
 (0)