Skip to content

Commit

Permalink
CR fix
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Sep 28, 2023
1 parent 9a81918 commit 5f52680
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions src/WebdriverClassicDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ public function setValue(
}
return;
}
$this->assertString($value, "Value for $widgetType must be a string");
if (!is_string($value)) {
throw new DriverException("Value for $widgetType must be a string");
}
$this->selectOptionOnElement($element, $value);
return;

Expand All @@ -395,14 +397,18 @@ public function setValue(
throw new DriverException(sprintf($message, $xpath));

case 'color':
$this->assertString($value, "Value for $widgetType must be a string");
if (!is_string($value)) {
throw new DriverException("Value for $widgetType must be a string");
}
// one cannot simply type into a color field, nor clear it
$this->setElementDomProperty($element, 'value', $value);
break;

case 'date':
case 'time':
$this->assertString($value, "Value for $widgetType must be a string");
if (!is_string($value)) {
throw new DriverException("Value for $widgetType must be a string");
}
try {
$element->clear();
$element->sendKeys($value);
Expand All @@ -413,27 +419,35 @@ public function setValue(
break;

case 'checkbox':
$this->assertBool($value, "Value for $widgetType must be a boolean");
if (!is_bool($value)) {
throw new DriverException("Value for $widgetType must be a boolean");

Check warning on line 423 in src/WebdriverClassicDriver.php

View check run for this annotation

Codecov / codecov/patch

src/WebdriverClassicDriver.php#L423

Added line #L423 was not covered by tests
}
if ($element->isSelected() xor $value) {
$this->clickOnElement($element);
}
return;

case 'radio':
$this->assertString($value, "Value for $widgetType must be a string");
if (!is_string($value)) {
throw new DriverException("Value for $widgetType must be a string");
}
$this->selectRadioValue($element, $value);
return;

case 'file':
$this->assertString($value, "Value for $widgetType must be a string");
if (!is_string($value)) {
throw new DriverException("Value for $widgetType must be a string");
}
$element->sendKeys($value);
break;

case 'text':
case 'password':
case 'textarea':
default:
$this->assertString($value, "Value for $widgetType must be a string");
if (!is_string($value)) {
throw new DriverException("Value for $widgetType must be a string");
}
$element->clear();
$element->sendKeys($value);
break;
Expand Down Expand Up @@ -1140,32 +1154,6 @@ private function jsonEncode($value, string $action, string $field): string
}
}

/**
* @param mixed $value
* @throws DriverException
* @phpstan-assert string $value
* @todo When switching to PHP 8, this can be replaced with `is_string(..) or throw new DriverException(..);`
*/
private function assertString($value, string $message): void
{
if (!is_string($value)) {
throw new DriverException($message);
}
}

/**
* @param mixed $value
* @throws DriverException
* @phpstan-assert bool $value
* @todo When switching to PHP 8, this can be replaced with `is_bool(..) or throw new DriverException(..);`
*/
private function assertBool($value, string $message): void
{
if (!is_bool($value)) {
throw new DriverException($message);
}
}

/**
* @param mixed $value
* @throws DriverException
Expand Down

0 comments on commit 5f52680

Please sign in to comment.