From 31fbc217ec97c163082da8a12ddb0f9009d048f5 Mon Sep 17 00:00:00 2001
From: Martynas Sudintas <martynas.sudintas@ongr.io>
Date: Wed, 29 Apr 2015 13:42:42 +0300
Subject: [PATCH] Updated DSL unit tests to meet improvements

---
 Filter/AndFilterTest.php  | 32 ++++++++++++++------------------
 Filter/NotFilterTest.php  |  2 +-
 Filter/OrFilterTest.php   | 32 ++++++++++++++------------------
 Filter/PostFilterTest.php | 32 +++++++++-----------------------
 Query/QueryTest.php       | 13 ++++++++-----
 5 files changed, 46 insertions(+), 65 deletions(-)

diff --git a/Filter/AndFilterTest.php b/Filter/AndFilterTest.php
index 6767f08..a7fe515 100644
--- a/Filter/AndFilterTest.php
+++ b/Filter/AndFilterTest.php
@@ -20,7 +20,7 @@ class AndFilterTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetType()
     {
-        $filter = new AndFilter('', []);
+        $filter = new AndFilter([], []);
         $result = $filter->getType();
         $this->assertEquals('and', $result);
     }
@@ -56,12 +56,10 @@ class AndFilterTest extends \PHPUnit_Framework_TestCase
                 [$mockBuildeFfirstFilter],
                 [],
                 [
-                    'filters' => [
-                        0 => [
-                            'term' => [
-                                'test_field' => [
-                                    'test_value' => 'test',
-                                ],
+                    [
+                        'term' => [
+                            'test_field' => [
+                                'test_value' => 'test',
                             ],
                         ],
                     ],
@@ -72,19 +70,17 @@ class AndFilterTest extends \PHPUnit_Framework_TestCase
                 [$mockBuildeFfirstFilter, $mockBuilderSecondFilter],
                 [],
                 [
-                    'filters' => [
-                        0 => [
-                            'term' => [
-                                'test_field' => [
-                                    'test_value' => 'test',
-                                ],
+                    [
+                        'term' => [
+                            'test_field' => [
+                                'test_value' => 'test',
                             ],
                         ],
-                        1 => [
-                            'prefix' => [
-                                'test_field' => [
-                                    'test_value' => 'test',
-                                ],
+                    ],
+                    [
+                        'prefix' => [
+                            'test_field' => [
+                                'test_value' => 'test',
                             ],
                         ],
                     ],
diff --git a/Filter/NotFilterTest.php b/Filter/NotFilterTest.php
index 5edf07d..211bba1 100644
--- a/Filter/NotFilterTest.php
+++ b/Filter/NotFilterTest.php
@@ -20,7 +20,7 @@ class NotFilterTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetType()
     {
-        $filter = new NotFilter('', []);
+        $filter = new NotFilter();
         $this->assertEquals('not', $filter->getType());
     }
 
diff --git a/Filter/OrFilterTest.php b/Filter/OrFilterTest.php
index 44f8117..4e6e5fc 100644
--- a/Filter/OrFilterTest.php
+++ b/Filter/OrFilterTest.php
@@ -20,7 +20,7 @@ class OrFilterTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetType()
     {
-        $filter = new OrFilter('', []);
+        $filter = new OrFilter();
         $result = $filter->getType();
         $this->assertEquals('or', $result);
     }
@@ -56,12 +56,10 @@ class OrFilterTest extends \PHPUnit_Framework_TestCase
                 [$mockBuilderFirstFilter],
                 [],
                 [
-                    'filters' => [
-                        0 => [
-                            'term' => [
-                                'test_field' => [
-                                    'test_value' => 'test',
-                                ],
+                    [
+                        'term' => [
+                            'test_field' => [
+                                'test_value' => 'test',
                             ],
                         ],
                     ],
@@ -72,19 +70,17 @@ class OrFilterTest extends \PHPUnit_Framework_TestCase
                 [$mockBuilderFirstFilter, $mockBuilderSecondFilter],
                 [],
                 [
-                    'filters' => [
-                        0 => [
-                            'term' => [
-                                'test_field' => [
-                                    'test_value' => 'test',
-                                ],
+                    [
+                        'term' => [
+                            'test_field' => [
+                                'test_value' => 'test',
                             ],
                         ],
-                        1 => [
-                            'prefix' => [
-                                'test_field' => [
-                                    'test_value' => 'test',
-                                ],
+                    ],
+                    [
+                        'prefix' => [
+                            'test_field' => [
+                                'test_value' => 'test',
                             ],
                         ],
                     ],
diff --git a/Filter/PostFilterTest.php b/Filter/PostFilterTest.php
index 747f2ce..9b60ff1 100644
--- a/Filter/PostFilterTest.php
+++ b/Filter/PostFilterTest.php
@@ -39,33 +39,19 @@ class PostFilterTest extends \PHPUnit_Framework_TestCase
     public function testAddFilter()
     {
         $missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
-            ->setMethods(['addToBool'])
             ->disableOriginalConstructor()
             ->getMock();
-        $missingFilterMock->expects($this->once())
-            ->method('addToBool')
-            ->withAnyParameters();
+        $missingFilterMock
+            ->expects($this->once())
+            ->method('toArray')
+            ->willReturn([]);
+        $missingFilterMock
+            ->expects($this->once())
+            ->method('getType')
+            ->willReturn('test_type');
 
         $postFilter = new PostFilter();
         $postFilter->setFilter($missingFilterMock);
-        $postFilter->addFilter($missingFilterMock, 'test');
-    }
-
-    /**
-     * Test setBoolParameters method.
-     */
-    public function testSetBoolParameters()
-    {
-        $missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
-            ->setMethods(['setParameters'])
-            ->disableOriginalConstructor()
-            ->getMock();
-        $missingFilterMock->expects($this->once())
-            ->method('setParameters')
-            ->withAnyParameters();
-
-        $postFilter = new PostFilter();
-        $postFilter->setFilter($missingFilterMock);
-        $postFilter->setBoolParameters(['test_param']);
+        $this->assertEquals(['test_type' => []], $postFilter->toArray());
     }
 }
diff --git a/Query/QueryTest.php b/Query/QueryTest.php
index b900702..e2ffd57 100644
--- a/Query/QueryTest.php
+++ b/Query/QueryTest.php
@@ -36,14 +36,17 @@ class QueryTest extends \PHPUnit_Framework_TestCase
      */
     public function testAddQuery()
     {
-        $missingFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
+        $missingFilterMock = $this
+            ->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter')
             ->disableOriginalConstructor()
-            ->setMethods(['addToBool'])
+            ->setMethods(['add'])
             ->getMock();
-        $missingFilterMock->expects($this->once())
-            ->method('addToBool')
+        $missingFilterMock
+            ->expects($this->once())
+            ->method('add')
             ->withAnyParameters();
-        $postFilterMock = $this->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\PostFilter')
+        $postFilterMock = $this
+            ->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Filter\PostFilter')
             ->disableOriginalConstructor()
             ->getMock();
 
-- 
GitLab