From f93b3c25e3216a2c8661fd3392171211ff9eb78f Mon Sep 17 00:00:00 2001
From: Mantas Varatiejus <mantas.varatiejus@nfq.com>
Date: Tue, 26 Jan 2016 15:04:34 +0200
Subject: [PATCH] Cover query classes with tests

---
 src/Query/BoostingQuery.php                |  4 +-
 src/Query/CommonTermsQuery.php             |  4 +-
 src/Query/ConstantScoreQuery.php           |  4 +-
 src/Query/DisMaxQuery.php                  |  6 +-
 src/Query/FuzzyQuery.php                   |  4 +-
 src/Query/IdsQuery.php                     |  2 +
 src/Query/MatchQuery.php                   |  4 +-
 src/Query/MoreLikeThisQuery.php            | 14 ++--
 src/Query/MultiMatchQuery.php              |  4 +-
 src/Query/QueryStringQuery.php             |  4 +-
 src/Query/RangeQuery.php                   |  4 +-
 src/Query/SimpleQueryStringQuery.php       |  4 +-
 src/Query/WildcardQuery.php                |  4 +-
 tests/Query/BoolQueryTest.php              |  2 +-
 tests/Query/BoostingQueryTest.php          | 40 ++++++++++++
 tests/Query/CommonTermsQueryTest.php       | 35 ++++++++++
 tests/Query/ConstantScoreQueryTest.php     | 41 ++++++++++++
 tests/Query/DisMaxQueryTest.php            | 44 +++++++++++++
 tests/Query/FuzzyQueryTest.php             | 35 ++++++++++
 tests/Query/IdsQueryTest.php               | 32 +++++++++
 tests/Query/IndicesQueryTest.php           | 75 ++++++++++++++++++++++
 tests/Query/MatchAllQueryTest.php          | 26 ++++++++
 tests/Query/MatchQueryTest.php             | 34 ++++++++++
 tests/Query/MoreLikeThisQueryTest.php      | 33 ++++++++++
 tests/Query/MultiMatchQueryTest.php        | 33 ++++++++++
 tests/Query/PrefixQueryTest.php            | 34 ++++++++++
 tests/Query/QueryStringQueryTest.php       | 32 +++++++++
 tests/Query/RangeQueryTest.php             | 35 ++++++++++
 tests/Query/RegexpQueryTest.php            | 34 ++++++++++
 tests/Query/SimpleQueryStringQueryTest.php | 32 +++++++++
 tests/Query/TermQueryTest.php              | 32 +++++++++
 tests/Query/TermsQueryTest.php             | 32 +++++++++
 tests/Query/WildcardQueryTest.php          | 34 ++++++++++
 33 files changed, 738 insertions(+), 19 deletions(-)
 create mode 100644 tests/Query/BoostingQueryTest.php
 create mode 100644 tests/Query/CommonTermsQueryTest.php
 create mode 100644 tests/Query/ConstantScoreQueryTest.php
 create mode 100644 tests/Query/DisMaxQueryTest.php
 create mode 100644 tests/Query/FuzzyQueryTest.php
 create mode 100644 tests/Query/IdsQueryTest.php
 create mode 100644 tests/Query/IndicesQueryTest.php
 create mode 100644 tests/Query/MatchAllQueryTest.php
 create mode 100644 tests/Query/MatchQueryTest.php
 create mode 100644 tests/Query/MoreLikeThisQueryTest.php
 create mode 100644 tests/Query/MultiMatchQueryTest.php
 create mode 100644 tests/Query/PrefixQueryTest.php
 create mode 100644 tests/Query/QueryStringQueryTest.php
 create mode 100644 tests/Query/RangeQueryTest.php
 create mode 100644 tests/Query/RegexpQueryTest.php
 create mode 100644 tests/Query/SimpleQueryStringQueryTest.php
 create mode 100644 tests/Query/TermQueryTest.php
 create mode 100644 tests/Query/TermsQueryTest.php
 create mode 100644 tests/Query/WildcardQueryTest.php

diff --git a/src/Query/BoostingQuery.php b/src/Query/BoostingQuery.php
index c88f0eb..2e6fe64 100644
--- a/src/Query/BoostingQuery.php
+++ b/src/Query/BoostingQuery.php
@@ -14,7 +14,9 @@ namespace ONGR\ElasticsearchDSL\Query;
 use ONGR\ElasticsearchDSL\BuilderInterface;
 
 /**
- * Elasticsearch boosting query class.
+ * Represents Elasticsearch "boosting" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html
  */
 class BoostingQuery implements BuilderInterface
 {
diff --git a/src/Query/CommonTermsQuery.php b/src/Query/CommonTermsQuery.php
index def85c0..aa1dfc7 100644
--- a/src/Query/CommonTermsQuery.php
+++ b/src/Query/CommonTermsQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Common terms query class.
+ * Represents Elasticsearch "common" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
  */
 class CommonTermsQuery implements BuilderInterface
 {
diff --git a/src/Query/ConstantScoreQuery.php b/src/Query/ConstantScoreQuery.php
index bafba28..6ec1150 100644
--- a/src/Query/ConstantScoreQuery.php
+++ b/src/Query/ConstantScoreQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Constant score query class.
+ * Represents Elasticsearch "constant_score" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html
  */
 class ConstantScoreQuery implements BuilderInterface
 {
diff --git a/src/Query/DisMaxQuery.php b/src/Query/DisMaxQuery.php
index 49c68b9..aee0d33 100644
--- a/src/Query/DisMaxQuery.php
+++ b/src/Query/DisMaxQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch dis max query class.
+ * Represents Elasticsearch "dis_max" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html
  */
 class DisMaxQuery implements BuilderInterface
 {
@@ -65,7 +67,7 @@ class DisMaxQuery implements BuilderInterface
     {
         $query = [];
         foreach ($this->queries as $type) {
-            $query = array_merge($query, $type->toArray());
+            $query[] = $type->toArray();
         }
         $output = $this->processArray(['queries' => $query]);
 
diff --git a/src/Query/FuzzyQuery.php b/src/Query/FuzzyQuery.php
index 27f8846..c5feb00 100644
--- a/src/Query/FuzzyQuery.php
+++ b/src/Query/FuzzyQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch fuzzy query class.
+ * Represents Elasticsearch "fuzzy" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
  */
 class FuzzyQuery implements BuilderInterface
 {
diff --git a/src/Query/IdsQuery.php b/src/Query/IdsQuery.php
index fa55b73..02028cc 100644
--- a/src/Query/IdsQuery.php
+++ b/src/Query/IdsQuery.php
@@ -18,6 +18,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
  * Represents Elasticsearch "ids" query.
  *
  * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html
+ *
+ * @todo Add "type" support
  */
 class IdsQuery implements BuilderInterface
 {
diff --git a/src/Query/MatchQuery.php b/src/Query/MatchQuery.php
index 05f799a..0bc220e 100644
--- a/src/Query/MatchQuery.php
+++ b/src/Query/MatchQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch match query class.
+ * Represents Elasticsearch "match" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
  */
 class MatchQuery implements BuilderInterface
 {
diff --git a/src/Query/MoreLikeThisQuery.php b/src/Query/MoreLikeThisQuery.php
index ce4e492..7be6953 100644
--- a/src/Query/MoreLikeThisQuery.php
+++ b/src/Query/MoreLikeThisQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch more_like_this query class.
+ * Represents Elasticsearch "more_like_this" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html
  */
 class MoreLikeThisQuery implements BuilderInterface
 {
@@ -24,15 +26,15 @@ class MoreLikeThisQuery implements BuilderInterface
     /**
      * @var string The text to find documents like it, required if ids or docs are not specified.
      */
-    private $likeText;
+    private $like;
 
     /**
-     * @param string $likeText
+     * @param string $like
      * @param array  $parameters
      */
-    public function __construct($likeText, array $parameters = [])
+    public function __construct($like, array $parameters = [])
     {
-        $this->likeText = $likeText;
+        $this->like = $like;
         $this->setParameters($parameters);
     }
 
@@ -52,7 +54,7 @@ class MoreLikeThisQuery implements BuilderInterface
         $query = [];
 
         if (($this->hasParameter('ids') === false) || ($this->hasParameter('docs') === false)) {
-            $query['like_text'] = $this->likeText;
+            $query['like'] = $this->like;
         }
 
         $output = $this->processArray($query);
diff --git a/src/Query/MultiMatchQuery.php b/src/Query/MultiMatchQuery.php
index 0fab953..35d0eec 100644
--- a/src/Query/MultiMatchQuery.php
+++ b/src/Query/MultiMatchQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch multi_match query class.
+ * Represents Elasticsearch "multi_match" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
  */
 class MultiMatchQuery implements BuilderInterface
 {
diff --git a/src/Query/QueryStringQuery.php b/src/Query/QueryStringQuery.php
index 5863bb9..3a8cb52 100644
--- a/src/Query/QueryStringQuery.php
+++ b/src/Query/QueryStringQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch query_string query class.
+ * Represents Elasticsearch "query_string" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
  */
 class QueryStringQuery implements BuilderInterface
 {
diff --git a/src/Query/RangeQuery.php b/src/Query/RangeQuery.php
index 75c446a..486009d 100644
--- a/src/Query/RangeQuery.php
+++ b/src/Query/RangeQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Range query class.
+ * Represents Elasticsearch "range" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
  */
 class RangeQuery implements BuilderInterface
 {
diff --git a/src/Query/SimpleQueryStringQuery.php b/src/Query/SimpleQueryStringQuery.php
index 960f04d..a110c5b 100644
--- a/src/Query/SimpleQueryStringQuery.php
+++ b/src/Query/SimpleQueryStringQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch simple_query_string query class.
+ * Represents Elasticsearch "simple_query_string" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html
  */
 class SimpleQueryStringQuery implements BuilderInterface
 {
diff --git a/src/Query/WildcardQuery.php b/src/Query/WildcardQuery.php
index a998221..6447769 100644
--- a/src/Query/WildcardQuery.php
+++ b/src/Query/WildcardQuery.php
@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
 use ONGR\ElasticsearchDSL\ParametersTrait;
 
 /**
- * Elasticsearch wildcard query class.
+ * Represents Elasticsearch "wildcard" query.
+ *
+ * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html
  */
 class WildcardQuery implements BuilderInterface
 {
diff --git a/tests/Query/BoolQueryTest.php b/tests/Query/BoolQueryTest.php
index af0cce8..d08dfe1 100644
--- a/tests/Query/BoolQueryTest.php
+++ b/tests/Query/BoolQueryTest.php
@@ -9,7 +9,7 @@
  * file that was distributed with this source code.
  */
 
-namespace ONGR\ElasticsearchDSL\Tests\Aggregation;
+namespace ONGR\ElasticsearchDSL\Tests\Query;
 
 use ONGR\ElasticsearchDSL\Query\BoolQuery;
 use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
diff --git a/tests/Query/BoostingQueryTest.php b/tests/Query/BoostingQueryTest.php
new file mode 100644
index 0000000..516f9b1
--- /dev/null
+++ b/tests/Query/BoostingQueryTest.php
@@ -0,0 +1,40 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\BoostingQuery;
+
+class BoostingQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $mock = $this->getMock('ONGR\ElasticsearchDSL\BuilderInterface');
+        $mock
+            ->expects($this->any())
+            ->method('toArray')
+            ->willReturn(['term' => ['foo' => 'bar']]);
+
+        $query = new BoostingQuery($mock, $mock, 0.2);
+        $expected = [
+            'boosting' => [
+                'positive' => ['term' => ['foo' => 'bar']],
+                'negative' => ['term' => ['foo' => 'bar']],
+                'negative_boost' => 0.2,
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/CommonTermsQueryTest.php b/tests/Query/CommonTermsQueryTest.php
new file mode 100644
index 0000000..749bb58
--- /dev/null
+++ b/tests/Query/CommonTermsQueryTest.php
@@ -0,0 +1,35 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\CommonTermsQuery;
+
+class CommonTermsQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new CommonTermsQuery('body', 'this is bonsai cool', ['cutoff_frequency' => 0.01]);
+        $expected = [
+            'common' => [
+                'body' => [
+                    'query' => 'this is bonsai cool',
+                    'cutoff_frequency' => 0.01,
+                ],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/ConstantScoreQueryTest.php b/tests/Query/ConstantScoreQueryTest.php
new file mode 100644
index 0000000..4c4fdb6
--- /dev/null
+++ b/tests/Query/ConstantScoreQueryTest.php
@@ -0,0 +1,41 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\ConstantScoreQuery;
+
+class ConstantScoreQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $mock = $this->getMock('ONGR\ElasticsearchDSL\BuilderInterface');
+        $mock
+            ->expects($this->any())
+            ->method('toArray')
+            ->willReturn(['term' => ['foo' => 'bar']]);
+
+        $query = new ConstantScoreQuery($mock, ['boost' => 1.2]);
+        $expected = [
+            'constant_score' => [
+                'filter' => [
+                    'term' => ['foo' => 'bar']
+                ],
+                'boost' => 1.2,
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/DisMaxQueryTest.php b/tests/Query/DisMaxQueryTest.php
new file mode 100644
index 0000000..8c5e442
--- /dev/null
+++ b/tests/Query/DisMaxQueryTest.php
@@ -0,0 +1,44 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\DisMaxQuery;
+
+class DisMaxQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $mock = $this->getMock('ONGR\ElasticsearchDSL\BuilderInterface');
+        $mock
+            ->expects($this->any())
+            ->method('toArray')
+            ->willReturn(['term' => ['foo' => 'bar']]);
+
+        $query = new DisMaxQuery(['boost' => 1.2]);
+        $query->addQuery($mock);
+        $query->addQuery($mock);
+        $expected = [
+            'dis_max' => [
+                'queries' => [
+                    ['term' => ['foo' => 'bar']],
+                    ['term' => ['foo' => 'bar']],
+                ],
+                'boost' => 1.2,
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/FuzzyQueryTest.php b/tests/Query/FuzzyQueryTest.php
new file mode 100644
index 0000000..16edbf7
--- /dev/null
+++ b/tests/Query/FuzzyQueryTest.php
@@ -0,0 +1,35 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\FuzzyQuery;
+
+class FuzzyQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new FuzzyQuery('user', 'ki', ['boost' => 1.2]);
+        $expected = [
+            'fuzzy' => [
+                'user' => [
+                    'value' => 'ki',
+                    'boost' => 1.2,
+                ],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/IdsQueryTest.php b/tests/Query/IdsQueryTest.php
new file mode 100644
index 0000000..f4ef6af
--- /dev/null
+++ b/tests/Query/IdsQueryTest.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\IdsQuery;
+
+class IdsQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new IdsQuery(['foo', 'bar']);
+        $expected = [
+            'ids' => [
+                'values' => ['foo', 'bar'],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/IndicesQueryTest.php b/tests/Query/IndicesQueryTest.php
new file mode 100644
index 0000000..ba384a2
--- /dev/null
+++ b/tests/Query/IndicesQueryTest.php
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\IndicesQuery;
+
+class IndicesQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Data provider for testToArray().
+     *
+     * @return array
+     */
+    public function getTestToArrayData()
+    {
+        $mock = $this->getMock('ONGR\ElasticsearchDSL\BuilderInterface');
+        $mock
+            ->expects($this->any())
+            ->method('toArray')
+            ->willReturn(['term' => ['foo' => 'bar']]);
+
+        return [
+            [
+                $mock,
+                $mock,
+                [
+                    'indices' => ['foo', 'bar'],
+                    'query' => ['term' => ['foo' => 'bar']],
+                    'no_match_query' => ['term' => ['foo' => 'bar']],
+                ]
+            ],
+            [
+                $mock,
+                'all',
+                [
+                    'indices' => ['foo', 'bar'],
+                    'query' => ['term' => ['foo' => 'bar']],
+                    'no_match_query' => 'all',
+                ]
+            ],
+            [
+                $mock,
+                null,
+                [
+                    'indices' => ['foo', 'bar'],
+                    'query' => ['term' => ['foo' => 'bar']],
+                ]
+            ],
+        ];
+    }
+
+    /**
+     * Tests toArray().
+     *
+     * @param $query
+     * @param $noMatchQuery
+     * @param $expected
+     *
+     * @dataProvider getTestToArrayData()
+     */
+    public function testToArray($query, $noMatchQuery, $expected)
+    {
+        $query = new IndicesQuery(['foo', 'bar'], $query, $noMatchQuery);
+        $this->assertEquals(['indices' => $expected], $query->toArray());
+    }
+}
diff --git a/tests/Query/MatchAllQueryTest.php b/tests/Query/MatchAllQueryTest.php
new file mode 100644
index 0000000..86c7cae
--- /dev/null
+++ b/tests/Query/MatchAllQueryTest.php
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
+
+class MatchAllQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new MatchAllQuery();
+        $this->assertEquals(['match_all' => []], $query->toArray());
+    }
+}
diff --git a/tests/Query/MatchQueryTest.php b/tests/Query/MatchQueryTest.php
new file mode 100644
index 0000000..af9597b
--- /dev/null
+++ b/tests/Query/MatchQueryTest.php
@@ -0,0 +1,34 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\MatchQuery;
+
+class MatchQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new MatchQuery('message', 'this is a test');
+        $expected = [
+            'match' => [
+                'message' => [
+                    'query' => 'this is a test',
+                ],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/MoreLikeThisQueryTest.php b/tests/Query/MoreLikeThisQueryTest.php
new file mode 100644
index 0000000..876c57e
--- /dev/null
+++ b/tests/Query/MoreLikeThisQueryTest.php
@@ -0,0 +1,33 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\MoreLikeThisQuery;
+
+class MoreLikeThisQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new MoreLikeThisQuery('this is a test', ['fields' => ['title', 'description']]);
+        $expected = [
+            'more_like_this' => [
+                'fields' => ['title', 'description'],
+                'like' => 'this is a test',
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/MultiMatchQueryTest.php b/tests/Query/MultiMatchQueryTest.php
new file mode 100644
index 0000000..428625f
--- /dev/null
+++ b/tests/Query/MultiMatchQueryTest.php
@@ -0,0 +1,33 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\MultiMatchQuery;
+
+class MultiMatchQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new MultiMatchQuery(['message', 'title'], 'this is a test');
+        $expected = [
+            'multi_match' => [
+                'query' => 'this is a test',
+                'fields' => ['message', 'title'],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/PrefixQueryTest.php b/tests/Query/PrefixQueryTest.php
new file mode 100644
index 0000000..18e9183
--- /dev/null
+++ b/tests/Query/PrefixQueryTest.php
@@ -0,0 +1,34 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\PrefixQuery;
+
+class PrefixQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new PrefixQuery('user', 'ki');
+        $expected = [
+            'prefix' => [
+                'user' => [
+                    'value' => 'ki',
+                ],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/QueryStringQueryTest.php b/tests/Query/QueryStringQueryTest.php
new file mode 100644
index 0000000..c211bd6
--- /dev/null
+++ b/tests/Query/QueryStringQueryTest.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\QueryStringQuery;
+
+class QueryStringQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new QueryStringQuery('this AND that OR thus');
+        $expected = [
+            'query_string' => [
+                'query' => 'this AND that OR thus',
+            ]
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/RangeQueryTest.php b/tests/Query/RangeQueryTest.php
new file mode 100644
index 0000000..430815f
--- /dev/null
+++ b/tests/Query/RangeQueryTest.php
@@ -0,0 +1,35 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\RangeQuery;
+
+class RangeQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new RangeQuery('age', ['gte' => 10, 'lte' => 20]);
+        $expected = [
+            'range' => [
+                'age' => [
+                    'gte' => 10,
+                    'lte' => 20,
+                ],
+            ]
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/RegexpQueryTest.php b/tests/Query/RegexpQueryTest.php
new file mode 100644
index 0000000..c7c583a
--- /dev/null
+++ b/tests/Query/RegexpQueryTest.php
@@ -0,0 +1,34 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\RegexpQuery;
+
+class RegexpQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new RegexpQuery('user', 's.*y');
+        $expected = [
+            'regexp' => [
+                'user' => [
+                    'value' => 's.*y',
+                ],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/SimpleQueryStringQueryTest.php b/tests/Query/SimpleQueryStringQueryTest.php
new file mode 100644
index 0000000..a92aeb7
--- /dev/null
+++ b/tests/Query/SimpleQueryStringQueryTest.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\SimpleQueryStringQuery;
+
+class SimpleQueryStringQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new SimpleQueryStringQuery('"fried eggs" +(eggplant | potato) -frittata');
+        $expected = [
+            'simple_query_string' => [
+                'query' => '"fried eggs" +(eggplant | potato) -frittata',
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/TermQueryTest.php b/tests/Query/TermQueryTest.php
new file mode 100644
index 0000000..688e3da
--- /dev/null
+++ b/tests/Query/TermQueryTest.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\TermQuery;
+
+class TermQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new TermQuery('user', 'bob');
+        $expected = [
+            'term' => [
+                'user' => 'bob',
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/TermsQueryTest.php b/tests/Query/TermsQueryTest.php
new file mode 100644
index 0000000..1291847
--- /dev/null
+++ b/tests/Query/TermsQueryTest.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\TermsQuery;
+
+class TermsQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests toArray().
+     */
+    public function testToArray()
+    {
+        $query = new TermsQuery('user', ['bob', 'elasticsearch']);
+        $expected = [
+            'terms' => [
+                'user' => ['bob', 'elasticsearch'],
+            ],
+        ];
+
+        $this->assertEquals($expected, $query->toArray());
+    }
+}
diff --git a/tests/Query/WildcardQueryTest.php b/tests/Query/WildcardQueryTest.php
new file mode 100644
index 0000000..e736df2
--- /dev/null
+++ b/tests/Query/WildcardQueryTest.php
@@ -0,0 +1,34 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Query;
+
+use ONGR\ElasticsearchDSL\Query\WildcardQuery;
+
+class WildcardQueryTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Test for query toArray() method.
+     */
+    public function testToArray()
+    {
+        $query = new WildcardQuery('user', 'ki*y');
+        $expectedResult = [
+            'wildcard' => [
+                'user' => [
+                    'value' => 'ki*y',
+                ],
+            ],
+        ];
+
+        $this->assertEquals($expectedResult, $query->toArray());
+    }
+}
-- 
GitLab