diff --git a/src/Aggregation/PercentilesAggregation.php b/src/Aggregation/PercentilesAggregation.php index d8890854b7da1ca2f6b461c9d0df7ee00bdb563c..3f203c497d8d84df08f1370b15bde05ce0809d4c 100644 --- a/src/Aggregation/PercentilesAggregation.php +++ b/src/Aggregation/PercentilesAggregation.php @@ -32,6 +32,25 @@ class PercentilesAggregation extends AbstractAggregation */ private $compression; + /** + * Inner aggregations container init. + * + * @param string $name + * @param string $field + * @param array $percents + * @param string $script + * @param int $compression + */ + public function __construct($name, $field = null, $percents = null, $script = null, $compression = null) + { + parent::__construct($name); + + $this->setField($field); + $this->setPercents($percents); + $this->setScript($script); + $this->setCompression($compression); + } + /** * @return array */ diff --git a/tests/Aggregation/PercentilesAggregationTest.php b/tests/Aggregation/PercentilesAggregationTest.php index 9ab92e4e6e4260aef7651a1b4e954abcddace258..b4492f42d416b986e7f66425b33f27506a3659c7 100644 --- a/tests/Aggregation/PercentilesAggregationTest.php +++ b/tests/Aggregation/PercentilesAggregationTest.php @@ -26,4 +26,28 @@ class PercentilesAggregationTest extends \PHPUnit_Framework_TestCase $aggregation = new PercentilesAggregation('bar'); $aggregation->getArray(); } + + /** + * Test getType method. + */ + public function testGetType() + { + $aggregation = new PercentilesAggregation('bar'); + $this->assertEquals('percentiles', $aggregation->getType()); + } + + /** + * Test getArray method. + */ + public function testGetArray() + { + $aggregation = new PercentilesAggregation('bar', 'fieldValue', ['percentsValue']); + $this->assertSame( + [ + 'percents' => ['percentsValue'], + 'field' => 'fieldValue', + ], + $aggregation->getArray() + ); + } }