From e2ac23aebfc62e63d32e7c219fea6be58ef05c5f Mon Sep 17 00:00:00 2001 From: Aivaras Gotovskis <aivaras.gotovskis@ongr.io> Date: Thu, 2 Jul 2015 13:51:07 +0300 Subject: [PATCH] Add parameters to nested query. --- src/Query/NestedQuery.php | 17 +++++++++++------ tests/Query/NestedQueryTest.php | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Query/NestedQuery.php b/src/Query/NestedQuery.php index 7229d16..b9196fa 100644 --- a/src/Query/NestedQuery.php +++ b/src/Query/NestedQuery.php @@ -12,12 +12,15 @@ namespace ONGR\ElasticsearchDSL\Query; use ONGR\ElasticsearchDSL\BuilderInterface; +use ONGR\ElasticsearchDSL\ParametersTrait; /** * Elasticsearch nested query class. */ class NestedQuery implements BuilderInterface { + use ParametersTrait; + /** * @var string */ @@ -51,11 +54,13 @@ class NestedQuery implements BuilderInterface */ public function toArray() { - return [ - 'path' => $this->path, - 'query' => [ - $this->query->getType() => $this->query->toArray(), - ], - ]; + return $this->processArray( + [ + 'path' => $this->path, + 'query' => [ + $this->query->getType() => $this->query->toArray(), + ], + ] + ); } } diff --git a/tests/Query/NestedQueryTest.php b/tests/Query/NestedQueryTest.php index 4b51d9d..6958369 100644 --- a/tests/Query/NestedQueryTest.php +++ b/tests/Query/NestedQueryTest.php @@ -40,4 +40,21 @@ class NestedQueryTest extends \PHPUnit_Framework_TestCase $query = new NestedQuery('test_path', $missingFilterMock); $this->assertEquals($result, $query->toArray()); } + + /** + * Tests if Nested Query has parameters. + */ + public function testParameters() + { + $nestedQuery = $this->getMockBuilder('ONGR\ElasticsearchDSL\Query\NestedQuery') + ->disableOriginalConstructor() + ->setMethods(null) + ->getMock(); + + $this->assertTrue(method_exists($nestedQuery, 'addParameter'), 'Nested query must have addParameter method'); + $this->assertTrue(method_exists($nestedQuery, 'setParameters'), 'Nested query must have setParameters method'); + $this->assertTrue(method_exists($nestedQuery, 'getParameters'), 'Nested query must have getParameters method'); + $this->assertTrue(method_exists($nestedQuery, 'hasParameter'), 'Nested query must have hasParameter method'); + $this->assertTrue(method_exists($nestedQuery, 'getParameter'), 'Nested query must have getParameter method'); + } } -- GitLab