Skip to content

Commit

Permalink
Merge v1.x into v2.x (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
mongodb-php-bot committed Sep 16, 2024
2 parents 6a6e904 + f2842bc commit 33dec57
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
20 changes: 15 additions & 5 deletions generator/config/expression/round.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ type:
- resolvesToLong
encode: array
description: |
Rounds a number to to a whole integer or to a specified decimal place.
Rounds a number to a whole integer or to a specified decimal place.
arguments:
-
name: number
type:
- resolvesToInt
- resolvesToDouble
- resolvesToDecimal
- resolvesToLong
- resolvesToNumber
description: |
Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long.
$round returns an error if the expression resolves to a non-numeric data type.
Expand All @@ -38,3 +35,16 @@ tests:
$round:
- '$value'
- 1
-
name: 'Round Average Rating'
pipeline:
-
$project:
roundedAverageRating:
$avg:
-
$round:
-
$avg:
- '$averageRating'
- 2
6 changes: 3 additions & 3 deletions src/Builder/Expression/FactoryTrait.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/Builder/Expression/RoundOperator.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions tests/Builder/Expression/Pipelines.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/Builder/Expression/RoundOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,22 @@ public function testExample(): void

$this->assertSamePipeline(Pipelines::RoundExample, $pipeline);
}

public function testRoundAverageRating(): void
{
$pipeline = new Pipeline(
Stage::project(
roundedAverageRating: Expression::avg(
Expression::round(
Expression::avg(
Expression::doubleFieldPath('averageRating'),
),
2,
),
),
),
);

$this->assertSamePipeline(Pipelines::RoundRoundAverageRating, $pipeline);
}
}

0 comments on commit 33dec57

Please sign in to comment.