From 131775219f84ac441d2e6568a541e2d36b5059b2 Mon Sep 17 00:00:00 2001
From: Aivaras Gotovskis <aivaras.gotovskis@ongr.io>
Date: Thu, 9 Jul 2015 15:59:47 +0300
Subject: [PATCH] Add constructor arguments to PercentileRanksAggregation.

---
 .../PercentileRanksAggregation.php            | 20 ++++++++++++-
 .../PercentileRanksAggregationTest.php        | 28 +++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/src/Aggregation/PercentileRanksAggregation.php b/src/Aggregation/PercentileRanksAggregation.php
index bc8a7fb..20f839e 100644
--- a/src/Aggregation/PercentileRanksAggregation.php
+++ b/src/Aggregation/PercentileRanksAggregation.php
@@ -32,6 +32,25 @@ class PercentileRanksAggregation extends AbstractAggregation
      */
     private $compression;
 
+    /**
+     * Inner aggregations container init.
+     *
+     * @param string $name
+     * @param string $field
+     * @param array  $values
+     * @param string $script
+     * @param int    $compression
+     */
+    public function __construct($name, $field = null, $values = null, $script = null, $compression = null)
+    {
+        parent::__construct($name);
+
+        $this->setField($field);
+        $this->setValues($values);
+        $this->setScript($script);
+        $this->setCompression($compression);
+    }
+
     /**
      * @return array
      */
@@ -98,7 +117,6 @@ class PercentileRanksAggregation extends AbstractAggregation
      * @param array $a
      *
      * @return bool
-     *
      * @throws \LogicException
      */
     private function isRequiredParametersSet($a)
diff --git a/tests/Aggregation/PercentileRanksAggregationTest.php b/tests/Aggregation/PercentileRanksAggregationTest.php
index 5ac3485..94ce741 100644
--- a/tests/Aggregation/PercentileRanksAggregationTest.php
+++ b/tests/Aggregation/PercentileRanksAggregationTest.php
@@ -62,4 +62,32 @@ class PercentileRanksAggregationTest extends \PHPUnit_Framework_TestCase
         $this->agg->setScript('bar');
         $this->agg->toArray();
     }
+
+    /**
+     * Test getType method.
+     */
+    public function testGetType()
+    {
+        $this->assertEquals('percentile_ranks', $this->agg->getType());
+    }
+
+    /**
+     * Test toArray method.
+     */
+    public function testToArray()
+    {
+        $this->agg->setField('bar');
+        $this->agg->setValues(['bar']);
+        $this->assertSame(
+            [
+                'agg_foo' => [
+                    'percentile_ranks' => [
+                        'field' => 'bar',
+                        'values' => ['bar'],
+                    ],
+                ],
+            ],
+            $this->agg->toArray()
+        );
+    }
 }
-- 
GitLab