From f4779a900606118e1f3ade44a0da80a726f4d5df Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Wed, 4 Aug 2021 20:39:24 +0800 Subject: [PATCH] add test --- .../MongoDB/Tests/Aggregation/BuilderTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php index 1d52a40580..80edd42d3c 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php @@ -16,6 +16,7 @@ use Documents\CmsComment; use Documents\GuestServer; use Documents\Tag; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\UTCDateTime; use function array_keys; @@ -199,6 +200,34 @@ public function testAggregationBuilder() $this->assertSame(3, $results[0]->numPosts); } + public function testAggregationBuilderResetHydration(): void + { + $this->insertTestData(); + + $builder = $this->dm->createAggregationBuilder(BlogPost::class)->hydrate(BlogTagAggregation::class); + + $resultCursor = $builder + ->hydrate(null) + ->unwind('$tags') + ->group() + ->field('id') + ->expression('$tags') + ->field('numPosts') + ->sum(1) + ->sort('numPosts', 'desc') + ->getAggregation() + ->getIterator(); + + $this->assertInstanceOf(Iterator::class, $resultCursor); + + $results = $resultCursor->toArray(); + $this->assertCount(2, $results); + $this->assertIsArray($results[0]); + $this->assertInstanceOf(ObjectId::class, $results[0]['_id']['$id']); + $this->assertSame('Tag', $results[0]['_id']['$ref']); + $this->assertSame(3, $results[0]['numPosts']); + } + public function testGetAggregation() { $this->insertTestData();