Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

PHPLIB-1343 Add tests on Array Expression Operators #22

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 12, 2024

Fix PHPLIB-1343

  • $arrayElemAt
  • $arrayToObject
  • $concatArrays
  • $filter
  • $firstN (already done)
  • $in
  • $indexOfArray
  • $isArray
  • $lastN (already done)
  • $map
  • $maxN
  • $minN
  • $objectToArray (skipped duplicate example with $arrayToObject)
  • $range
  • $reduce
  • $reverseArray
  • $size
  • $slice
  • $sortArray
  • $zip (already done)

@GromNaN GromNaN requested a review from alcaeus January 12, 2024 10:42
@@ -3,12 +3,31 @@ name: $isArray
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/'
type:
- resolvesToBool
encode: array
encode: single
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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"
Copy link
Member Author

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;
Copy link
Member Author

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.

Copy link
Member

@alcaeus alcaeus left a 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.

@GromNaN GromNaN merged commit 5e8b98a into mongodb:0.1 Jan 15, 2024
@GromNaN GromNaN deleted the PHPLIB-1343 branch January 15, 2024 11:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants