diff --git a/src/Query/NestedQuery.php b/src/Query/NestedQuery.php index 7229d164b156b4418e2ca2af018d6798ac73181e..b9196fae736de8357d070f41a7ce116e5affdec1 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 4b51d9d4e81431e37a01cf621ab08ce98ae3653b..69583698a2d5ca641676660f42e5dcbf1060af1b 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'); + } }