From ffb35940efacddefb47e3e3c3048c740fa49d4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= <saimaz@users.noreply.github.com> Date: Thu, 31 May 2018 11:37:28 +0300 Subject: [PATCH] fix bool query when the body is empty (#263) --- src/Query/Compound/BoolQuery.php | 4 ++++ tests/Unit/Query/Compound/BoolQueryTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Query/Compound/BoolQuery.php b/src/Query/Compound/BoolQuery.php index 4b30287..7bb6a85 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 b2e3da1..995c492 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. */ -- GitLab