diff --git a/composer.json b/composer.json index e8f1a03..f7cae58 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ }, "require-dev": { "mink/driver-testsuite": "dev-master", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-phpunit": "^1.3", + "phpstan/phpstan": "^2", + "phpstan/phpstan-phpunit": "^2", "phpunit/phpunit": "^9.6.8", "symfony/error-handler": "^5.4 || ^6.0 || ^7.0", "symfony/process": "^5.4 || ^6.0 || ^7.0", diff --git a/phpstan.dist.neon b/phpstan.dist.neon index f0dc8e8..7639a1a 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -3,7 +3,7 @@ includes: - vendor/phpstan/phpstan-phpunit/rules.neon parameters: - level: 9 + level: 10 paths: - src - tests @@ -26,3 +26,13 @@ parameters: identifier: argument.type count: 1 path: src/WebdriverClassicDriver.php + - + message: '#^Method Mink\\WebdriverClassicDriver\\WebdriverClassicDriver\:\:getWindowHandleFromName\(\) should return string but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/WebdriverClassicDriver.php + - + message: '#^Parameter \#1 \$handle of method Facebook\\WebDriver\\Remote\\RemoteTargetLocator\:\:window\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 3 + path: src/WebdriverClassicDriver.php diff --git a/src/WebdriverClassicDriver.php b/src/WebdriverClassicDriver.php index 47c18f7..1f3e7a8 100644 --- a/src/WebdriverClassicDriver.php +++ b/src/WebdriverClassicDriver.php @@ -670,10 +670,6 @@ public function executeScript( $this->getWebDriver()->executeScript($script); } - /** - * {@inheritdoc} - * @return mixed - */ public function evaluateScript( #[Language('JavaScript')] string $script @@ -971,7 +967,7 @@ private function executeJsOnXpath( * @throws DriverException */ private function executeJsOnElement( - RemoteWebElement $element, + WebDriverElement $element, #[Language('JavaScript')] string $script ) { @@ -1044,7 +1040,7 @@ private function getWindowHandleFromName(string $name): string } } - private function clickOnElement(RemoteWebElement $element): void + private function clickOnElement(WebDriverElement $element): void { $element->getLocationOnScreenOnceScrolledIntoView(); $element->click(); @@ -1108,14 +1104,11 @@ private function withWindow(?string $name, callable $callback): void */ private function findElement( #[Language('XPath')] - string $xpath, - ?RemoteWebElement $parent = null + string $xpath ): RemoteWebElement { try { $finder = WebDriverBy::xpath($xpath); - return $parent - ? $parent->findElement($finder) - : $this->getWebDriver()->findElement($finder); + return $this->getWebDriver()->findElement($finder); } catch (\Throwable $e) { throw new DriverException("Failed to find element: {$e->getMessage()}", 0, $e); } @@ -1124,7 +1117,7 @@ private function findElement( /** * @throws DriverException */ - private function selectRadioValue(RemoteWebElement $element, string $value): void + private function selectRadioValue(WebDriverElement $element, string $value): void { try { (new WebDriverRadios($element))->selectByValue($value); @@ -1142,7 +1135,7 @@ private function selectRadioValue(RemoteWebElement $element, string $value): voi /** * @throws DriverException */ - private function selectOptionOnElement(RemoteWebElement $element, string $value, bool $multiple = false): void + private function selectOptionOnElement(WebDriverElement $element, string $value, bool $multiple = false): void { try { $select = new WebDriverSelect($element); @@ -1172,7 +1165,7 @@ private function selectOptionOnElement(RemoteWebElement $element, string $value, * * @throws DriverException */ - private function deselectAllOptions(RemoteWebElement $element): void + private function deselectAllOptions(WebDriverElement $element): void { try { (new WebDriverSelect($element))->deselectAll(); @@ -1190,7 +1183,7 @@ private function deselectAllOptions(RemoteWebElement $element): void * @throws DriverException */ private function ensureInputType( - RemoteWebElement $element, + WebDriverElement $element, #[Language('XPath')] string $xpath, string $type, @@ -1233,7 +1226,7 @@ private function jsonEncode($value, string $action, string $field): string * @param mixed $value * @throws DriverException */ - private function setElementDomProperty(RemoteWebElement $element, string $property, $value): void + private function setElementDomProperty(WebDriverElement $element, string $property, $value): void { $this->executeJsOnElement( $element, diff --git a/tests/WebdriverClassicConfig.php b/tests/WebdriverClassicConfig.php index f3d19bd..3dbd06d 100644 --- a/tests/WebdriverClassicConfig.php +++ b/tests/WebdriverClassicConfig.php @@ -21,7 +21,10 @@ public static function getInstance(): self public function createDriver(): WebdriverClassicDriver { - $seleniumHost = $_SERVER['DRIVER_URL']; + $seleniumHost = $_SERVER['DRIVER_URL'] ?? null; + if (!is_string($seleniumHost)) { + throw new \RuntimeException('Selenium host must be specified (as a string) in $_SERVER[DRIVER_URL].'); + } return new WebdriverClassicDriver($this->getBrowserName(), [], $seleniumHost); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d4d3a01..59207f1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,9 +4,8 @@ use Symfony\Component\Process\Process; -$minkTestServerPort = isset($_SERVER['WEB_FIXTURES_HOST']) - ? parse_url($_SERVER['WEB_FIXTURES_HOST'], PHP_URL_PORT) - : '8002'; +$fixturesHost = $_SERVER['WEB_FIXTURES_HOST'] ?? ''; +$minkTestServerPort = parse_url(is_string($fixturesHost) ? $fixturesHost : '', PHP_URL_PORT) ?: '8002'; $minkTestServer = new Process([ PHP_BINARY,