From 6788a7e8b4170359674fa92332c68885871af029 Mon Sep 17 00:00:00 2001
From: Aivaras Gotovskis <aivaras.gotovskis@ongr.io>
Date: Thu, 9 Jul 2015 15:57:06 +0300
Subject: [PATCH] Test constructor arguments to FiltersAggregation.

---
 tests/Aggregation/FiltersAggregationTest.php | 59 ++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/tests/Aggregation/FiltersAggregationTest.php b/tests/Aggregation/FiltersAggregationTest.php
index 4f541be..af8c21f 100644
--- a/tests/Aggregation/FiltersAggregationTest.php
+++ b/tests/Aggregation/FiltersAggregationTest.php
@@ -12,6 +12,7 @@
 namespace ONGR\ElasticsearchDSL\Tests\Unit\DSL\Aggregation;
 
 use ONGR\ElasticsearchDSL\Aggregation\FiltersAggregation;
+use ONGR\ElasticsearchDSL\BuilderInterface;
 
 /**
  * Unit test for filters aggregation.
@@ -97,4 +98,62 @@ class FiltersAggregationTest extends \PHPUnit_Framework_TestCase
         ];
         $this->assertEquals($expected, $results);
     }
+
+    /**
+     * Tests if filters can be passed to constructor.
+     */
+    public function testConstructorFilter()
+    {
+        /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface1 */
+        $builderInterface1 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface');
+        $builderInterface1->expects($this->any())->method('getType')->willReturn('type1');
+        /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface2 */
+        $builderInterface2 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface');
+        $builderInterface2->expects($this->any())->method('getType')->willReturn('type2');
+
+        $aggregation = new FiltersAggregation(
+            'test',
+            [
+                'filter1' => $builderInterface1,
+                'filter2' => $builderInterface2,
+            ]
+        );
+
+        $this->assertSame(
+            [
+                'agg_test' => [
+                    'filters' => [
+                        'filters' => [
+                            'filter1' => ['type1' => null],
+                            'filter2' => ['type2' => null],
+                        ],
+                    ],
+                ],
+            ],
+            $aggregation->toArray()
+        );
+
+        $aggregation = new FiltersAggregation(
+            'test',
+            [
+                'filter1' => $builderInterface1,
+                'filter2' => $builderInterface2,
+            ],
+            true
+        );
+
+        $this->assertSame(
+            [
+                'agg_test' => [
+                    'filters' => [
+                        'filters' => [
+                            ['type1' => null],
+                            ['type2' => null],
+                        ],
+                    ],
+                ],
+            ],
+            $aggregation->toArray()
+        );
+    }
 }
-- 
GitLab