Skip to content

Commit d01e823

Browse files
oleg-andreyevOndraM
authored andcommitted
Make sure that chromeOptions is an object when empty
1 parent 99ec34e commit d01e823

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

lib/Chrome/ChromeOptions.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,19 @@ public function toCapabilities()
117117
}
118118

119119
/**
120-
* @return array
120+
* @return \ArrayObject|array
121121
*/
122122
public function toArray()
123123
{
124-
$options = $this->experimentalOptions;
125-
126124
// The selenium server expects a 'dictionary' instead of a 'list' when
127125
// reading the chrome option. However, an empty array in PHP will be
128-
// converted to a 'list' instead of a 'dictionary'. To fix it, we always
129-
// set the 'binary' to avoid returning an empty array.
130-
$options['binary'] = $this->binary;
126+
// converted to a 'list' instead of a 'dictionary'. To fix it, we work
127+
// with `ArrayObject`
128+
$options = new \ArrayObject($this->experimentalOptions);
129+
130+
if (!empty($this->binary)) {
131+
$options['binary'] = $this->binary;
132+
}
131133

132134
if (!empty($this->arguments)) {
133135
$options['args'] = $this->arguments;

lib/Remote/DesiredCapabilities.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ public function toW3cCompatibleArray()
235235
// Convert ChromeOptions
236236
if (array_key_exists(ChromeOptions::CAPABILITY, $ossCapabilities)) {
237237
if (array_key_exists(ChromeOptions::CAPABILITY_W3C, $ossCapabilities)) {
238-
$w3cCapabilities[ChromeOptions::CAPABILITY_W3C] = array_merge_recursive(
239-
$ossCapabilities[ChromeOptions::CAPABILITY],
240-
$ossCapabilities[ChromeOptions::CAPABILITY_W3C]
238+
$w3cCapabilities[ChromeOptions::CAPABILITY_W3C] = new \ArrayObject(
239+
array_merge_recursive(
240+
(array) $ossCapabilities[ChromeOptions::CAPABILITY],
241+
(array) $ossCapabilities[ChromeOptions::CAPABILITY_W3C]
242+
)
241243
);
242244
} else {
243245
$w3cCapabilities[ChromeOptions::CAPABILITY_W3C] = $ossCapabilities[ChromeOptions::CAPABILITY];

tests/unit/Remote/DesiredCapabilitiesTest.php

+19-9
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,24 @@ public function provideW3cCapabilities()
213213
'vendor:prefix' => 'vendor extension should be kept',
214214
],
215215
],
216+
'chromeOptions should be an object if empty' => [
217+
new DesiredCapabilities([
218+
ChromeOptions::CAPABILITY => new ChromeOptions(),
219+
]),
220+
[
221+
'goog:chromeOptions' => new \ArrayObject(),
222+
],
223+
],
216224
'chromeOptions should be converted' => [
217225
new DesiredCapabilities([
218226
ChromeOptions::CAPABILITY => $chromeOptions,
219227
]),
220228
[
221-
'goog:chromeOptions' => [
222-
'args' => ['--headless'],
223-
'binary' => '',
224-
],
229+
'goog:chromeOptions' => new \ArrayObject(
230+
[
231+
'args' => ['--headless'],
232+
]
233+
),
225234
],
226235
],
227236
'chromeOptions should be merged if already defined' => [
@@ -233,11 +242,12 @@ public function provideW3cCapabilities()
233242
],
234243
]),
235244
[
236-
'goog:chromeOptions' => [
237-
'args' => ['--headless', 'window-size=1024,768'],
238-
'binary' => '',
239-
'debuggerAddress' => '127.0.0.1:38947',
240-
],
245+
'goog:chromeOptions' => new \ArrayObject(
246+
[
247+
'args' => ['--headless', 'window-size=1024,768'],
248+
'debuggerAddress' => '127.0.0.1:38947',
249+
]
250+
),
241251
],
242252
],
243253
'firefox_profile should be converted' => [

0 commit comments

Comments
 (0)