Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 9a9ab00

Browse files
committed
Improve codestyle and type-safety comparisons
1 parent 62b0221 commit 9a9ab00

7 files changed

+14
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/).
1313
- Allow installation of Symfony 5 components.
1414
- Rename environment variable used to pass path to ChromeDriver executable from `webdriver.chrome.driver` to `WEBDRIVER_CHROME_DRIVER`. However the old one also still works to keep backward compatibility
1515
- If subdirectories in a path to screenshot destination does not exists (using `takeScreenshot()` or `takeElementScreenshot()` methods), they are automatically created.
16+
- When zip archive cannot be crated during file upload, throw exception instead of silently returning false.
1617

1718
### Fixed
1819
- `WebDriverExpectedCondition::presenceOfElementLocated()` works correctly when used within `WebDriverExpectedCondition::not()`.

lib/AbstractWebDriverCheckboxOrRadio.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ protected function getRelatedElements($value = null)
211211
$form = $this->element->findElement(WebDriverBy::xpath('ancestor::form'));
212212

213213
$formId = $form->getAttribute('id');
214-
if (!$formId) {
214+
if ($formId === '' || $formId === null) {
215215
return $form->findElements(WebDriverBy::xpath(
216216
sprintf('.//input[@name = %s%s]', XPathEscaper::escapeQuotes($this->name), $valueSelector)
217217
));

lib/Chrome/ChromeOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ public function toArray()
142142
// set the 'binary' to avoid returning an empty array.
143143
$options['binary'] = $this->binary;
144144

145-
if ($this->arguments) {
145+
if (!empty($this->arguments)) {
146146
$options['args'] = $this->arguments;
147147
}
148148

149-
if ($this->extensions) {
149+
if (!empty($this->extensions)) {
150150
$options['extensions'] = $this->extensions;
151151
}
152152

lib/Remote/HttpCommandExecutor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public function execute(WebDriverCommand $command)
295295
}
296296
}
297297

298-
if ($params && is_array($params) && $http_method !== 'POST') {
298+
if (is_array($params) && !empty($params) && $http_method !== 'POST') {
299299
throw new BadMethodCallException(sprintf(
300300
'The http method called for %s is %s but it has to be POST' .
301301
' if you want to pass the JSON params %s',
@@ -325,7 +325,7 @@ public function execute(WebDriverCommand $command)
325325
$encoded_params = null;
326326

327327
if ($http_method === 'POST') {
328-
if ($params && is_array($params)) {
328+
if (is_array($params) && !empty($params)) {
329329
$encoded_params = json_encode($params);
330330
} elseif ($this->isW3cCompliant) {
331331
// POST body must be valid JSON in W3C, even if empty: https://www.w3.org/TR/webdriver/#processing-model
@@ -343,7 +343,7 @@ public function execute(WebDriverCommand $command)
343343
$http_method,
344344
$url
345345
);
346-
if ($params && is_array($params)) {
346+
if (is_array($params) && !empty($params)) {
347347
$msg .= sprintf(' with params: %s', json_encode($params));
348348
}
349349

lib/Remote/RemoteWebDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public function takeScreenshot($save_as = null)
378378
$this->execute(DriverCommand::SCREENSHOT)
379379
);
380380

381-
if ($save_as) {
381+
if ($save_as !== null) {
382382
$directoryPath = dirname($save_as);
383383

384384
if (!file_exists($directoryPath)) {

lib/Remote/RemoteWebElement.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public function takeElementScreenshot($save_as = null)
446446
)
447447
);
448448

449-
if ($save_as) {
449+
if ($save_as !== null) {
450450
$directoryPath = dirname($save_as);
451451
if (!file_exists($directoryPath)) {
452452
mkdir($directoryPath, 0777, true);
@@ -505,9 +505,10 @@ protected function upload($local_file)
505505
// Create a temporary file in the system temp directory.
506506
$temp_zip = tempnam(sys_get_temp_dir(), 'WebDriverZip');
507507
$zip = new ZipArchive();
508-
if ($zip->open($temp_zip, ZipArchive::CREATE) !== true) {
509-
return false;
508+
if (($errorCode = $zip->open($temp_zip, ZipArchive::CREATE)) !== true) {
509+
throw new WebDriverException(sprintf('Error creating zip archive: %s', $errorCode));
510510
}
511+
511512
$info = pathinfo($local_file);
512513
$file_name = $info['basename'];
513514
$zip->addFile($local_file, $file_name);

lib/Remote/WebDriverCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class WebDriverCommand
2727
/**
2828
* @param string $session_id
2929
* @param string $name Constant from DriverCommand
30-
* @param array $parameters Array of
30+
* @param array $parameters
31+
* @todo In 2.0 force parameters to be an array, then remove is_array() checks in HttpCommandExecutor
3132
*/
3233
public function __construct($session_id, $name, $parameters)
3334
{

0 commit comments

Comments
 (0)