Skip to content

Commit

Permalink
fix bool query when the body is empty (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
saimaz authored May 31, 2018
1 parent 4e7e235 commit ffb3594
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Query/Compound/BoolQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public function toArray()

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

if (empty($output)) {
$output = new \stdClass();
}

return [$this->getType() => $output];
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Query/Compound/BoolQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public function testBoolToArray()
$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.
*/
Expand Down

0 comments on commit ffb3594

Please sign in to comment.