Skip to content
Snippets Groups Projects
Commit b581a8d1 authored by Simonas Šerlinskas's avatar Simonas Šerlinskas
Browse files

fixed issues with array conversion from empty array to {}

parent 92123ed0
No related branches found
No related tags found
No related merge requests found
...@@ -77,7 +77,7 @@ class ReverseNestedAggregation extends AbstractAggregation ...@@ -77,7 +77,7 @@ class ReverseNestedAggregation extends AbstractAggregation
$output = new \stdClass(); $output = new \stdClass();
if ($this->getPath()) { if ($this->getPath()) {
$output['path'] = $this->getPath(); $output = ['path' => $this->getPath()];
} }
return $output; return $output;
......
...@@ -56,12 +56,16 @@ class TermQuery implements BuilderInterface ...@@ -56,12 +56,16 @@ class TermQuery implements BuilderInterface
*/ */
public function toArray() public function toArray()
{ {
$query = [ $query = $this->processArray();
'value' => $this->value,
]; if (empty($query)) {
$query = $this->value;
} else {
$query['value'] = $this->value;
}
$output = [ $output = [
$this->field => $this->processArray($query), $this->field => $query,
]; ];
return $output; return $output;
......
...@@ -28,7 +28,7 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase ...@@ -28,7 +28,7 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase
$aggregation = new GlobalAggregation('test_agg'); $aggregation = new GlobalAggregation('test_agg');
$result = [ $result = [
'global' => [], 'global' => new \stdClass(),
]; ];
$out[] = [ $out[] = [
...@@ -42,7 +42,7 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase ...@@ -42,7 +42,7 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase
$aggregation->addAggregation($aggregation2); $aggregation->addAggregation($aggregation2);
$result = [ $result = [
'global' => [], 'global' => new \stdClass(),
'aggregations' => [ 'aggregations' => [
$aggregation2->getName() => $aggregation2->toArray(), $aggregation2->getName() => $aggregation2->toArray(),
], ],
...@@ -66,7 +66,10 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase ...@@ -66,7 +66,10 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase
*/ */
public function testToArray($aggregation, $expectedResult) public function testToArray($aggregation, $expectedResult)
{ {
$this->assertEquals($expectedResult, $aggregation->toArray()); $this->assertEquals(
json_encode($expectedResult),
json_encode($aggregation->toArray())
);
} }
/** /**
......
...@@ -66,12 +66,15 @@ class ReverseNestedAggregationTest extends \PHPUnit_Framework_TestCase ...@@ -66,12 +66,15 @@ class ReverseNestedAggregationTest extends \PHPUnit_Framework_TestCase
$aggregation->addAggregation($termAggregation); $aggregation->addAggregation($termAggregation);
$expectedResult = [ $expectedResult = [
'reverse_nested' => [], 'reverse_nested' => new \stdClass(),
'aggregations' => [ 'aggregations' => [
$termAggregation->getName() => $termAggregation->toArray(), $termAggregation->getName() => $termAggregation->toArray(),
], ],
]; ];
$this->assertEquals($expectedResult, $aggregation->toArray()); $this->assertEquals(
json_encode($expectedResult),
json_encode($aggregation->toArray())
);
} }
} }
...@@ -25,13 +25,13 @@ class TopHitsAggregationTest extends \PHPUnit_Framework_TestCase ...@@ -25,13 +25,13 @@ class TopHitsAggregationTest extends \PHPUnit_Framework_TestCase
*/ */
public function testToArray() public function testToArray()
{ {
$sort = new FieldSort('acme'); $sort = new FieldSort('acme', ['order' => 'asc']);
$aggregation = new TopHitsAggregation('acme', 1, 1, $sort); $aggregation = new TopHitsAggregation('acme', 1, 1, $sort);
$expected = [ $expected = [
'top_hits' => [ 'top_hits' => [
'sort' => [ 'sort' => [
'acme' => [], 'acme' => ['order' => 'asc'],
], ],
'size' => 1, 'size' => 1,
'from' => 1, 'from' => 1,
......
...@@ -41,7 +41,7 @@ class BoolQueryTest extends \PHPUnit_Framework_TestCase ...@@ -41,7 +41,7 @@ class BoolQueryTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($bool->isRelevant()); $this->assertFalse($bool->isRelevant());
$bool->add(new TermQuery('acme', 'foo'), BoolQuery::SHOULD); $bool->add(new TermQuery('acme', 'foo'), BoolQuery::SHOULD);
$this->assertFalse($bool->isRelevant()); $this->assertTrue($bool->isRelevant());
} }
/** /**
...@@ -61,7 +61,7 @@ class BoolQueryTest extends \PHPUnit_Framework_TestCase ...@@ -61,7 +61,7 @@ class BoolQueryTest extends \PHPUnit_Framework_TestCase
* Test for addToBool() without setting a correct bool operator. * Test for addToBool() without setting a correct bool operator.
* *
* @expectedException \UnexpectedValueException * @expectedException \UnexpectedValueException
* @expectedExceptionMessage The provided bool operator is not supported * @expectedExceptionMessage The bool operator acme is not supported
*/ */
public function testBoolAddToBoolException() public function testBoolAddToBoolException()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment