From 13dff0c03b64b3cff1d8f6d838c13ec1fd08cd01 Mon Sep 17 00:00:00 2001 From: Marc Morera Date: Fri, 10 Jun 2022 23:28:05 +0200 Subject: [PATCH] Added with metadata in result agg --- Result/Aggregation.php | 10 ++++++++++ Tests/Result/AggregationTest.php | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) 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()); + } }