From e55b5e7a61e0aa895f547168728863750536a175 Mon Sep 17 00:00:00 2001
From: Mantas Simkus <mantas.simkus@ongr.io>
Date: Mon, 23 Mar 2015 16:18:06 +0200
Subject: [PATCH] Improved DSL/Bool test for Elasticsearch bundle

---
 Bool/BoolTest.php | 61 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 2 deletions(-)

diff --git a/Bool/BoolTest.php b/Bool/BoolTest.php
index 097e352..c493dc9 100644
--- a/Bool/BoolTest.php
+++ b/Bool/BoolTest.php
@@ -13,6 +13,7 @@ namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Aggregation;
 
 use ONGR\ElasticsearchBundle\DSL\Bool\Bool;
 use ONGR\ElasticsearchBundle\DSL\Filter\MissingFilter;
+use ONGR\ElasticsearchBundle\DSL\Filter\TermFilter;
 
 /**
  * Unit test for Bool.
@@ -22,12 +23,68 @@ class BoolTest extends \PHPUnit_Framework_TestCase
     /**
      * Tests isRelevant method.
      */
-    public function testIsRelevant()
+    public function testBoolIsRelevant()
     {
         $bool = new Bool();
         $this->assertEquals(false, $bool->isRelevant());
-
         $bool->addToBool(new MissingFilter('test'));
         $this->assertEquals(true, $bool->isRelevant());
     }
+
+    /**
+     * Test for addToBool() without setting a correct bool operator.
+     *
+     * @expectedException        \UnexpectedValueException
+     * @expectedExceptionMessage The bool operator Should is not supported
+     */
+    public function testBoolAddToBoolException()
+    {
+        $bool = new Bool();
+        $bool->addToBool(new MissingFilter('test'), 'Should');
+    }
+
+    /**
+     * Tests toArray() method.
+     */
+    public function testBoolToArray()
+    {
+        $bool = new Bool();
+        $bool->addToBool(new TermFilter('key1', 'value1'), 'should');
+        $bool->addToBool(new TermFilter('key2', 'value2'), 'must');
+        $bool->addToBool(new TermFilter('key3', 'value3'), 'must_not');
+        $expected = [
+            'should' => [
+                [
+                    'term' => [
+                        'key1' => 'value1',
+                    ],
+                ],
+            ],
+            'must' => [
+                [
+                    'term' => [
+                        'key2' => 'value2',
+                    ],
+                ],
+            ],
+            'must_not' => [
+                [
+                    'term' => [
+                        'key3' => 'value3',
+                    ],
+                ],
+            ],
+        ];
+        $this->assertEquals($expected, $bool->toArray());
+    }
+
+    /**
+     * Test getType method.
+     */
+    public function testBoolGetType()
+    {
+        $bool = new Bool();
+        $result = $bool->getType();
+        $this->assertEquals('bool', $result);
+    }
 }
-- 
GitLab