-
Notifications
You must be signed in to change notification settings - Fork 4
PHPLIB-1359 Add tests on Accumulators ($group, $bucket, $bucketAuto, $setWindowFields) #29
Conversation
$operator = Yaml::parseFile($file->getPathname()); | ||
assert(is_array($operator)); | ||
$definitions[] = new OperatorDefinition(...$operator); | ||
$operator = Yaml::parseFile($file->getPathname(), Yaml::PARSE_OBJECT | Yaml::PARSE_OBJECT_FOR_MAP); |
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 option PARSE_OBJECT_FOR_MAP
is required to ensure the $count
empty object {}
from the Yaml is not converted to an empty array. []
@@ -63,6 +63,6 @@ public function __construct( | |||
|
|||
$this->arguments = array_merge($requiredArgs, $optionalArgs); | |||
|
|||
$this->tests = array_map(static fn (array $test): TestDefinition => new TestDefinition(...$test), array_values($tests)); | |||
$this->tests = array_map(static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), array_values($tests)); |
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 think this line of code is "expert" level.
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.
Splitting this line across multiple lines may just make it a little less "expert" and help tell the closure apart from the arg:
$this->tests = array_map(static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), array_values($tests)); | |
$this->tests = array_map( | |
static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), | |
array_values($tests), | |
); |
sortBy: object( | ||
orderDate: 1, | ||
), | ||
output: object( |
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'm always using the same way to write the pipelines (using object
and not array
map), so I don't really cover all the feature.
Expression::numberFieldPath('test03'), | ||
], | ||
p: [0.5, 0.95], | ||
method: 'approximate', |
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.
This should be an enum.
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.
Have one comment for legibility, but LGTM.
As for the topic of enums, I believe there are a couple of other places where we can consider using an enum (e.g. the unbounded
and current
identifiers for windows). These have the advantage of making possible values easier to discover.
@@ -63,6 +63,6 @@ public function __construct( | |||
|
|||
$this->arguments = array_merge($requiredArgs, $optionalArgs); | |||
|
|||
$this->tests = array_map(static fn (array $test): TestDefinition => new TestDefinition(...$test), array_values($tests)); | |||
$this->tests = array_map(static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), array_values($tests)); |
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.
Splitting this line across multiple lines may just make it a little less "expert" and help tell the closure apart from the arg:
$this->tests = array_map(static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), array_values($tests)); | |
$this->tests = array_map( | |
static fn (object $test): TestDefinition => new TestDefinition(...(array) $test), | |
array_values($tests), | |
); |
Since both values are often used together (at least in examples), we may also make an enum that return both. |
…$setWindowFields)
Fix PHPLIB-1359
https://www.mongodb.com/docs/manual/reference/operator/aggregation/#accumulators---group---bucket---bucketauto---setwindowfields-
For the operators that have accumulator and expression examples on the same page, I added the examples on both.
already done$accumulator
already done$addToSet
$avg
accumulator + expression$bottom
$bottomN
$count
the empty object required modifications in Yaml parsingalready done$first
$firstN
accumulator + expressionalready done$last
$lastN
$max
accumulator + expression$maxN
$median
accumulator + expression$mergeObjects
$min
accumulator + expression$percentile
accumulator + expression$push
$stdDevPop
accumulator + expression$stdDevSamp
accumulator + expression$sum
accumulator + expression$top
$topN