From e193da43d9a6f0bbd9bf425c535b32a6cd640fac Mon Sep 17 00:00:00 2001 From: pmishev Date: Wed, 1 Jul 2020 15:52:03 +0100 Subject: [PATCH 1/2] Allow null 'format' in DateRangeAggregation, as it is not required --- src/Aggregation/Bucketing/DateRangeAggregation.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Aggregation/Bucketing/DateRangeAggregation.php b/src/Aggregation/Bucketing/DateRangeAggregation.php index 3ca14e29..561e951a 100644 --- a/src/Aggregation/Bucketing/DateRangeAggregation.php +++ b/src/Aggregation/Bucketing/DateRangeAggregation.php @@ -128,17 +128,19 @@ function ($v) { */ public function getArray() { - if ($this->getField() && $this->getFormat() && !empty($this->ranges)) { + if ($this->getField() && !empty($this->ranges)) { $data = [ - 'format' => $this->getFormat(), 'field' => $this->getField(), 'ranges' => $this->ranges, 'keyed' => $this->keyed, ]; + if ($this->getFormat()) { + $data['format'] = $this->getFormat(); + } return $data; } - throw new \LogicException('Date range aggregation must have field, format set and range added.'); + throw new \LogicException('Date range aggregation must have field and range added.'); } /** From 7ba1d66dadb5967c6c6f964b60c087480015ccc8 Mon Sep 17 00:00:00 2001 From: pmishev Date: Wed, 1 Jul 2020 16:51:47 +0100 Subject: [PATCH 2/2] Fixed unit test --- tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php index 6a3c5dbe..aaa57385 100644 --- a/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php @@ -19,7 +19,7 @@ class DateRangeAggregationTest extends \PHPUnit\Framework\TestCase * Test if exception is thrown. * * @expectedException \LogicException - * @expectedExceptionMessage Date range aggregation must have field, format set and range added. + * @expectedExceptionMessage Date range aggregation must have field and range added. */ public function testIfExceptionIsThrownWhenNoParametersAreSet() {