Skip to content

Commit

Permalink
brought in PR ongr-io#316
Browse files Browse the repository at this point in the history
  • Loading branch information
Lindsay Snider committed Aug 27, 2021
1 parent 57505a4 commit 5804945
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Aggregation/Bucketing/RangeAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function ($v) {
}
);

if (!empty($key)) {
if ('' !== $key) {
$range['key'] = $key;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/Unit/Aggregation/Bucketing/RangeAggregationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,41 @@ public function testRangeAggregationAddRange()
$this->assertEquals($result, $aggregation->toArray());
}

public function testRangeAggregationAddZeroIndexedKeys()
{
$aggregation = new RangeAggregation('test_agg');
$aggregation->setKeyed(true);
$aggregation->setField('test_field');
$aggregation->addRange(0, 100, '0');
$aggregation->addRange(100, 200, '1');
$aggregation->addRange(200, 300);

$result = [
'range' => [
'field' => 'test_field',
'ranges' => [
[
'from' => 0,
'to' => 100,
'key' => '0'
],
[
'from' => 100,
'to' => 200,
'key' => '1'
],
[
'from' => 200,
'to' => 300
]
],
'keyed' => true
],
];

$this->assertEquals($result, $aggregation->toArray());
}

/**
* Test addRange method with multiple values.
*/
Expand Down

0 comments on commit 5804945

Please sign in to comment.