From c1add49278b72da1ab6da47c99ba16b96a1ef1a1 Mon Sep 17 00:00:00 2001
From: Aivaras Gotovskis <aivaras.gotovskis@ongr.io>
Date: Thu, 9 Jul 2015 16:00:11 +0300
Subject: [PATCH] Add constructor arguments to PercentilesAggregation.

---
 src/Aggregation/PercentilesAggregation.php    | 19 +++++++++++++++
 .../PercentilesAggregationTest.php            | 24 +++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/src/Aggregation/PercentilesAggregation.php b/src/Aggregation/PercentilesAggregation.php
index d889085..3f203c4 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 9ab92e4..b4492f4 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()
+        );
+    }
 }
-- 
GitLab