From 1fd0f88035292968b1ee5ed72a728b3a986aa74b Mon Sep 17 00:00:00 2001
From: LTRocky <rokasvaliukas@gmail.com>
Date: Fri, 6 Mar 2015 16:19:11 +0200
Subject: [PATCH] unit tests

---
 Aggregation/CardinalityAggregationTest.php | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/Aggregation/CardinalityAggregationTest.php b/Aggregation/CardinalityAggregationTest.php
index f0f4af2..68a0305 100644
--- a/Aggregation/CardinalityAggregationTest.php
+++ b/Aggregation/CardinalityAggregationTest.php
@@ -18,6 +18,42 @@ use ONGR\ElasticsearchBundle\DSL\Aggregation\CardinalityAggregation;
  */
 class CardinalityAggregationTest extends \PHPUnit_Framework_TestCase
 {
+    /**
+     * Tests getArray method.
+     */
+    public function testGetArray()
+    {
+        $aggregation = new CardinalityAggregation('bar');
+
+        // When $script is set.
+        $aggregation->setScript('foo');
+        $result = $aggregation->getArray();
+
+        $this->assertArrayHasKey('script', $result);
+        $this->assertEquals('foo', $result['script']);
+
+        // When $field is set.
+        $aggregation->setField('foo');
+        $result = $aggregation->getArray();
+
+        $this->assertArrayHasKey('field', $result);
+        $this->assertEquals('foo', $result['field']);
+
+        // When $precisionThreshold is set.
+        $aggregation->setPrecisionThreshold(10);
+        $result = $aggregation->getArray();
+
+        $this->assertArrayHasKey('precision_threshold', $result);
+        $this->assertEquals(10, $result['precision_threshold']);
+
+        // When $rehash is set.
+        $aggregation->setRehash(true);
+        $result = $aggregation->getArray();
+
+        $this->assertArrayHasKey('rehash', $result);
+        $this->assertEquals(true, $result['rehash']);
+    }
+
     /**
      * Tests if CardinalityAggregation#getArray throws exception when expected.
      *
@@ -29,4 +65,6 @@ class CardinalityAggregationTest extends \PHPUnit_Framework_TestCase
         $aggregation = new CardinalityAggregation('bar');
         $aggregation->getArray();
     }
+
+
 }
-- 
GitLab