-
Notifications
You must be signed in to change notification settings - Fork 4
PHPLIB-1343 Add tests on Array Expression Operators #22
Conversation
@@ -3,12 +3,31 @@ name: $isArray | |||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/' | |||
type: | |||
- resolvesToBool | |||
encode: array | |||
encode: single |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The syntax in the doc is confusing. It looks like the expression must be encapsulated in a single-value array, but in the example, the variable is used directly.
Maybe a doc issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is covered by this note in the docs:
Aggregation expressions accept a variable number of arguments. These arguments are normally passed as an array. However, when the argument is a single value, you can simplify your code by passing the argument directly without wrapping it in an array.
I'd have to do some tests on how values are handled. Looking at the examples in the Behavior section, we should make sure that passing a value of [1]
is actually recognised as an array, which might require changing encode
back to array
and updating the examples in the config files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, reverted to always use the array syntax.
"$multiply": [ | ||
"$$tempInCelsius", | ||
{ | ||
"$numberDouble": "1.8000000000000000444" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other example of numeric value incorrectly encoded.
Related to #21 (comment)
@@ -278,6 +278,8 @@ private function recursiveEncode(mixed $value): mixed | |||
foreach (get_object_vars($value) as $key => $val) { | |||
$value->{$key} = $this->recursiveEncode($val); | |||
} | |||
|
|||
return $value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a bug, but an optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion regarding argument encoding for $isArray
, but LGTM other than that.
Fix PHPLIB-1343
$arrayElemAt
$arrayToObject
$concatArrays
$filter
(already done)$firstN
$in
$indexOfArray
$isArray
(already done)$lastN
$map
$maxN
$minN
$objectToArray
(skipped duplicate example with$arrayToObject
)$range
$reduce
$reverseArray
$size
$slice
$sortArray
(already done)$zip