Skip to content

Commit ffb3594

Browse files
authored
fix bool query when the body is empty (#263)
1 parent 4e7e235 commit ffb3594

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: src/Query/Compound/BoolQuery.php

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public function toArray()
116116

117117
$output = $this->processArray($output);
118118

119+
if (empty($output)) {
120+
$output = new \stdClass();
121+
}
122+
119123
return [$this->getType() => $output];
120124
}
121125

Diff for: tests/Unit/Query/Compound/BoolQueryTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public function testBoolToArray()
6969
$this->assertEquals($expected, $bool->toArray());
7070
}
7171

72+
/**
73+
* Tests bool query with empty body if it forms \stdObject
74+
*/
75+
public function testEmptyBoolQuery()
76+
{
77+
$bool = new BoolQuery();
78+
79+
$this->assertEquals(['bool' => new \stdClass()], $bool->toArray());
80+
}
81+
7282
/**
7383
* Tests bool query in filter context.
7484
*/

0 commit comments

Comments
 (0)