Skip to content

Commit

Permalink
Fix Composite::addAfter(null)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainneutron committed Nov 23, 2020
1 parent 11ababf commit c137b2c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Aggregation/Composite.php
Expand Up @@ -25,6 +25,10 @@ public function addSource(AbstractAggregation $aggregation): self
*/
public function addAfter(?array $checkpoint): self
{
if (null === $checkpoint) {
return $this;
}

return $this->setParam('after', $checkpoint);
}
}
37 changes: 37 additions & 0 deletions tests/Aggregation/CompositeTest.php
Expand Up @@ -178,6 +178,43 @@ public function testCompositeWithAfterAggregation(): void
$this->assertEquals($expected, $results);
}

/**
* @group functional
*/
public function testCompositeWithNullAfter(): void
{
$composite = new Composite('products');
$composite->setSize(2);
$composite->addSource((new Terms('color'))->setField('color.keyword'));
$composite->addAfter(null);

$query = new Query();
$query->addAggregation($composite);

$results = $this->_getIndexForTest()->search($query)->getAggregation('products');
$expected = [
'after_key' => [
'color' => 'green',
],
'buckets' => [
[
'key' => [
'color' => 'blue',
],
'doc_count' => 2,
],
[
'key' => [
'color' => 'green',
],
'doc_count' => 1,
],
],
];

$this->assertEquals($expected, $results);
}

protected function _getIndexForTest(): Index
{
$index = $this->_createIndex();
Expand Down

0 comments on commit c137b2c

Please sign in to comment.