-
Notifications
You must be signed in to change notification settings - Fork 21
feat(cts): add requestOptions tests #501
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,39 +63,19 @@ private function normalize($options) | |
]; | ||
|
||
foreach ($options as $optionName => $value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After adding boolean tests, I realized PHP formatted booleans array like I also realized that we were handling query parameters twice (here, and in Could you please confirm it's correct to you? Tests pass correctly but better safe than sorry There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks fine ... But I'm pretty sure at some point I had the issue with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's now done directly here in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this is the only issue of that type, I think we're good. |
||
if (is_array($value)) { | ||
if ($optionName === 'headers') { | ||
$headersToLowerCase = []; | ||
if (is_array($value) && $optionName === 'headers') { | ||
$headersToLowerCase = []; | ||
|
||
foreach ($value as $key => $v) { | ||
$headersToLowerCase[mb_strtolower($key)] = $v; | ||
} | ||
|
||
$normalized[$optionName] = $this->format( | ||
$headersToLowerCase | ||
); | ||
} else { | ||
$normalized[$optionName] = $this->format( | ||
$value, | ||
$optionName === 'queryParameters' | ||
); | ||
foreach ($value as $key => $v) { | ||
$headersToLowerCase[mb_strtolower($key)] = $v; | ||
} | ||
|
||
$normalized[$optionName] = $headersToLowerCase; | ||
} else { | ||
$normalized[$optionName] = $value; | ||
} | ||
} | ||
|
||
return $normalized; | ||
} | ||
|
||
private function format($options, $isQueryParameters = false) | ||
{ | ||
foreach ($options as $name => $value) { | ||
if (is_array($value) && $isQueryParameters) { | ||
$options[$name] = implode(',', $value); | ||
} | ||
} | ||
|
||
return $options; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,18 @@ public static function buildQuery(array $args) | |
|
||
$args = array_map(function ($value) { | ||
if (is_array($value)) { | ||
return json_encode($value); | ||
// PHP converts `true,false` in arrays to `1,`, so we create strings instead | ||
// to avoid sending wrong values | ||
$values = array_map(function ($v) { | ||
if (is_bool($v)) { | ||
return $v ? 'true' : 'false'; | ||
} | ||
|
||
return $v; | ||
}, $value); | ||
|
||
// We then return the array as a string comma separated | ||
return implode(',', $values); | ||
Comment on lines
23
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what was duplicated in the |
||
} elseif (is_bool($value)) { | ||
return $value ? 'true' : 'false'; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.