diff --git a/Result/Aggregation.php b/Result/Aggregation.php index 9f04ab2..c2500e2 100644 --- a/Result/Aggregation.php +++ b/Result/Aggregation.php @@ -193,6 +193,16 @@ public function getMetadata(): array return $this->metadata; } + /** + * @param array $metadata + * + * @return void + */ + public function withMetadata(array $metadata) + { + $this->metadata = $metadata; + } + /** * Get all elements. * diff --git a/Tests/Result/AggregationTest.php b/Tests/Result/AggregationTest.php index d94d59e..d0bda41 100644 --- a/Tests/Result/AggregationTest.php +++ b/Tests/Result/AggregationTest.php @@ -249,4 +249,22 @@ public function testCreateFromArrayAllValues() $this->assertEquals(100, $aggregation->getTotalElements()); $this->assertCount(1, $aggregation->getActiveElements()); } + + /** + * @return void + */ + public function testWithMetadata() + { + $aggregation = Aggregation::createFromArray([ + 'name' => 'agg1', + 'counters' => [], + 'application_type' => Filter::MUST_ALL, + 'active_elements' => ['1'], + 'total_elements' => 100, + 'metadata' => ['a' => 1, 'b' => 2], + ]); + + $aggregation->withMetadata(['m']); + $this->assertEquals(['m'], $aggregation->getMetadata()); + } }