diff --git a/src/Query/Compound/BoolQuery.php b/src/Query/Compound/BoolQuery.php index 4b30287e2d0517572730050ca02606161403d489..7bb6a8594afec39731cfc704198eb3f2f3bbc5b7 100644 --- a/src/Query/Compound/BoolQuery.php +++ b/src/Query/Compound/BoolQuery.php @@ -116,6 +116,10 @@ class BoolQuery implements BuilderInterface $output = $this->processArray($output); + if (empty($output)) { + $output = new \stdClass(); + } + return [$this->getType() => $output]; } diff --git a/tests/Unit/Query/Compound/BoolQueryTest.php b/tests/Unit/Query/Compound/BoolQueryTest.php index b2e3da14d7cc5213ce0396bc79649ac3bf1c7901..995c492954164683b66ce91d9d4aecc819f2cac8 100644 --- a/tests/Unit/Query/Compound/BoolQueryTest.php +++ b/tests/Unit/Query/Compound/BoolQueryTest.php @@ -69,6 +69,16 @@ class BoolQueryTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $bool->toArray()); } + /** + * Tests bool query with empty body if it forms \stdObject + */ + public function testEmptyBoolQuery() + { + $bool = new BoolQuery(); + + $this->assertEquals(['bool' => new \stdClass()], $bool->toArray()); + } + /** * Tests bool query in filter context. */