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 fd83633
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed type-hint for `Elastica\QueryBuilder\DSL\Aggregation::sampler()` not consistent with the underlying constructor call [#1815](https://github.com/ruflin/Elastica/pull/1815)
* Replaced `_routing` and `_retry_on_conflict` by `routing` and `retry_on_conflict` in `AbstractUpdateAction` [#1807](https://github.com/ruflin/Elastica/issues/1807)
* Fixed `Elastica\Util::toSnakeCase()` with first letter being lower cased [#1831](https://github.com/ruflin/Elastica/pull/1831)
* Fix calling `Elastica\Aggregation\Composite::addAfter()` with the `null` value [1877](https://github.com/ruflin/Elastica/pull/1877)
### Security


Expand Down
4 changes: 4 additions & 0 deletions src/Aggregation/Composite.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 fd83633

Please sign in to comment.