Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed Aug 4, 2021
1 parent e18e9f4 commit f4779a9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f4779a9

Please sign in to comment.