Skip to content

Commit

Permalink
Fix the validation of invalid values in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Nov 29, 2023
1 parent 796b01f commit 042979b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/BrowserKitDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ public function setValue(string $xpath, $value)
return;
}

if (\is_array($value) || \is_bool($value)) {
throw new DriverException('Textual and file form fields don\'t support array or boolean values');
if (\is_array($value) || \is_bool($value) || $value === null) {

Check failure on line 426 in src/BrowserKitDriver.php

View workflow job for this annotation

GitHub Actions / Static analysis

Strict comparison using === between string and null will always evaluate to false.
throw new DriverException('Textual and file form fields don\'t support array, boolean or null values.');
}

$field->setValue($value);
Expand Down Expand Up @@ -592,6 +592,12 @@ protected function prepareUrl(string $url)
protected function getFormField(string $xpath)
{
$fieldNode = $this->getCrawlerNode($this->getFilteredCrawler($xpath));
$fieldType = $fieldNode->getAttribute('type');

if (\in_array($fieldType, ['button', 'submit', 'image'], true)) {
throw new DriverException(sprintf('Cannot access a form field of type "%s".', $fieldType));
}

$fieldName = str_replace('[]', '', $fieldNode->getAttribute('name'));

$formNode = $this->getFormNode($fieldNode);
Expand Down

0 comments on commit 042979b

Please sign in to comment.