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
$output = new \stdClass();
if ($this->getPath()) {
$output['path'] = $this->getPath();
$output = ['path' => $this->getPath()];
}
return $output;
......
......@@ -56,12 +56,16 @@ class TermQuery implements BuilderInterface
*/
public function toArray()
{
$query = [
'value' => $this->value,
];
$query = $this->processArray();
if (empty($query)) {
$query = $this->value;
} else {
$query['value'] = $this->value;
}
$output = [
$this->field => $this->processArray($query),
$this->field => $query,
];
return $output;
......
......@@ -28,7 +28,7 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase
$aggregation = new GlobalAggregation('test_agg');
$result = [
'global' => [],
'global' => new \stdClass(),
];
$out[] = [
......@@ -42,7 +42,7 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase
$aggregation->addAggregation($aggregation2);
$result = [
'global' => [],
'global' => new \stdClass(),
'aggregations' => [
$aggregation2->getName() => $aggregation2->toArray(),
],
......@@ -66,7 +66,10 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase
*/
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
$aggregation->addAggregation($termAggregation);
$expectedResult = [
'reverse_nested' => [],
'reverse_nested' => new \stdClass(),
'aggregations' => [
$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
*/
public function testToArray()
{
$sort = new FieldSort('acme');
$sort = new FieldSort('acme', ['order' => 'asc']);
$aggregation = new TopHitsAggregation('acme', 1, 1, $sort);
$expected = [
'top_hits' => [
'sort' => [
'acme' => [],
'acme' => ['order' => 'asc'],
],
'size' => 1,
'from' => 1,
......
......@@ -41,7 +41,7 @@ class BoolQueryTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($bool->isRelevant());
$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
* Test for addToBool() without setting a correct bool operator.
*
* @expectedException \UnexpectedValueException
* @expectedExceptionMessage The provided bool operator is not supported
* @expectedExceptionMessage The bool operator acme is not supported
*/
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