Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade phpstan; increase phpstan level; fix a few bugs #55

Merged
merged 8 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ includes:
- vendor/phpstan/phpstan-phpunit/rules.neon

parameters:
level: 9
level: 10
paths:
- src
- tests
Expand All @@ -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
25 changes: 9 additions & 16 deletions src/WebdriverClassicDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,6 @@ public function executeScript(
$this->getWebDriver()->executeScript($script);
}

/**
* {@inheritdoc}
* @return mixed
uuf6429 marked this conversation as resolved.
Show resolved Hide resolved
*/
public function evaluateScript(
#[Language('JavaScript')]
string $script
Expand Down Expand Up @@ -971,7 +967,7 @@ private function executeJsOnXpath(
* @throws DriverException
*/
private function executeJsOnElement(
RemoteWebElement $element,
WebDriverElement $element,
#[Language('JavaScript')]
string $script
) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1108,14 +1104,11 @@ private function withWindow(?string $name, callable $callback): void
*/
private function findElement(
#[Language('XPath')]
string $xpath,
?RemoteWebElement $parent = null
aik099 marked this conversation as resolved.
Show resolved Hide resolved
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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion tests/WebdriverClassicConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading