diff --git a/generator/config/expression/round.yaml b/generator/config/expression/round.yaml index 9bc6961c7..52e6004a0 100644 --- a/generator/config/expression/round.yaml +++ b/generator/config/expression/round.yaml @@ -8,12 +8,15 @@ type: - resolvesToLong encode: array description: | - Rounds a number to a whole integer or to a specified decimal place. + Rounds a number to to a whole integer or to a specified decimal place. arguments: - name: number type: - - resolvesToNumber + - resolvesToInt + - resolvesToDouble + - resolvesToDecimal + - resolvesToLong 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. @@ -35,16 +38,3 @@ tests: $round: - '$value' - 1 - - - name: 'Round Average Rating' - pipeline: - - - $project: - roundedAverageRating: - $avg: - - - $round: - - - $avg: - - '$averageRating' - - 2 diff --git a/src/Builder/Expression/FactoryTrait.php b/src/Builder/Expression/FactoryTrait.php index 78f460fa0..7828951ea 100644 --- a/src/Builder/Expression/FactoryTrait.php +++ b/src/Builder/Expression/FactoryTrait.php @@ -1546,15 +1546,15 @@ public static function reverseArray(PackedArray|ResolvesToArray|BSONArray|array } /** - * Rounds a number to a whole integer or to a specified decimal place. + * Rounds a number to to a whole integer or to a specified decimal place. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number 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. * @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. */ public static function round( - Decimal128|Int64|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number, Optional|ResolvesToInt|int $place = Optional::Undefined, ): RoundOperator { return new RoundOperator($number, $place); diff --git a/src/Builder/Expression/RoundOperator.php b/src/Builder/Expression/RoundOperator.php index 323ae99eb..7f3cad53e 100644 --- a/src/Builder/Expression/RoundOperator.php +++ b/src/Builder/Expression/RoundOperator.php @@ -15,7 +15,7 @@ use MongoDB\Builder\Type\Optional; /** - * Rounds a number to a whole integer or to a specified decimal place. + * Rounds a number to to a whole integer or to a specified decimal place. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/ */ @@ -24,21 +24,21 @@ class RoundOperator implements ResolvesToInt, ResolvesToDouble, ResolvesToDecima public const ENCODE = Encode::Array; /** - * @var Decimal128|Int64|ResolvesToNumber|float|int $number Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. + * @var Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number 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. */ - public readonly Decimal128|Int64|ResolvesToNumber|float|int $number; + public readonly Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number; /** @var Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. */ public readonly Optional|ResolvesToInt|int $place; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number 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. * @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number, Optional|ResolvesToInt|int $place = Optional::Undefined, ) { $this->number = $number; diff --git a/tests/Builder/Expression/Pipelines.php b/tests/Builder/Expression/Pipelines.php index f84d00984..f5a4bcec1 100644 --- a/tests/Builder/Expression/Pipelines.php +++ b/tests/Builder/Expression/Pipelines.php @@ -4266,32 +4266,6 @@ enum Pipelines: string ] JSON; - /** Round Average Rating */ - case RoundRoundAverageRating = <<<'JSON' - [ - { - "$project": { - "roundedAverageRating": { - "$avg": [ - { - "$round": [ - { - "$avg": [ - "$averageRating" - ] - }, - { - "$numberInt": "2" - } - ] - } - ] - } - } - } - ] - JSON; - /** * Example * diff --git a/tests/Builder/Expression/RoundOperatorTest.php b/tests/Builder/Expression/RoundOperatorTest.php index 758668818..accae5074 100644 --- a/tests/Builder/Expression/RoundOperatorTest.php +++ b/tests/Builder/Expression/RoundOperatorTest.php @@ -27,22 +27,4 @@ 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); - } } diff --git a/tests/Operation/WatchFunctionalTest.php b/tests/Operation/WatchFunctionalTest.php index 562192f1b..8715bb6b1 100644 --- a/tests/Operation/WatchFunctionalTest.php +++ b/tests/Operation/WatchFunctionalTest.php @@ -307,15 +307,15 @@ function (array $event) use (&$events): void { $this->assertCount(3, $events); $this->assertSame('getMore', $events[0]['started']->getCommandName()); - $this->assertArrayHasKey('failed', $events[0]); + $this->arrayHasKey('failed', $events[0]); $this->assertSame('aggregate', $events[1]['started']->getCommandName()); $this->assertResumeAfter($postBatchResumeToken, $events[1]['started']->getCommand()); - $this->assertArrayHasKey('succeeded', $events[1]); + $this->arrayHasKey('succeeded', $events[1]); // Original cursor is freed immediately after the change stream resumes $this->assertSame('killCursors', $events[2]['started']->getCommandName()); - $this->assertArrayHasKey('succeeded', $events[2]); + $this->arrayHasKey('succeeded', $events[2]); $this->assertFalse($changeStream->valid()); } @@ -380,15 +380,15 @@ function (array $event) use (&$events): void { $this->assertCount(3, $events); $this->assertSame('getMore', $events[0]['started']->getCommandName()); - $this->assertArrayHasKey('failed', $events[0]); + $this->arrayHasKey('failed', $events[0]); $this->assertSame('aggregate', $events[1]['started']->getCommandName()); $this->assertStartAtOperationTime($operationTime, $events[1]['started']->getCommand()); - $this->assertArrayHasKey('succeeded', $events[1]); + $this->arrayHasKey('succeeded', $events[1]); // Original cursor is freed immediately after the change stream resumes $this->assertSame('killCursors', $events[2]['started']->getCommandName()); - $this->assertArrayHasKey('succeeded', $events[2]); + $this->arrayHasKey('succeeded', $events[2]); $this->assertFalse($changeStream->valid()); }