diff --git a/src/Aggregation/ReverseNestedAggregation.php b/src/Aggregation/ReverseNestedAggregation.php index 58febb5f963880e66ec93cfc39693f5a2fb51778..55b58b232e27c2b223e3eb9cf923e6ae039dace0 100644 --- a/src/Aggregation/ReverseNestedAggregation.php +++ b/src/Aggregation/ReverseNestedAggregation.php @@ -77,7 +77,7 @@ class ReverseNestedAggregation extends AbstractAggregation $output = new \stdClass(); if ($this->getPath()) { - $output['path'] = $this->getPath(); + $output = ['path' => $this->getPath()]; } return $output; diff --git a/src/Query/TermQuery.php b/src/Query/TermQuery.php index 3a0bf24b60ce107b3a3784d3db6b4bfa8fd51702..e561721f0d864141cf2991d4af3813a7c44597c8 100644 --- a/src/Query/TermQuery.php +++ b/src/Query/TermQuery.php @@ -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; diff --git a/tests/Aggregation/GlobalAggregationTest.php b/tests/Aggregation/GlobalAggregationTest.php index 48fb372f59d9b2554de0db90037196a3f41d0eda..357eb4c6500f0da9613239944be29ffbdc93c895 100644 --- a/tests/Aggregation/GlobalAggregationTest.php +++ b/tests/Aggregation/GlobalAggregationTest.php @@ -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()) + ); } /** diff --git a/tests/Aggregation/ReverseNestedAggregationTest.php b/tests/Aggregation/ReverseNestedAggregationTest.php index 531c150102c3de63247cb7d80778a498d20166d4..0c797121fdc9839b97434199131483d9ac4e6f62 100644 --- a/tests/Aggregation/ReverseNestedAggregationTest.php +++ b/tests/Aggregation/ReverseNestedAggregationTest.php @@ -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()) + ); } } diff --git a/tests/Aggregation/TopHitsAggregationTest.php b/tests/Aggregation/TopHitsAggregationTest.php index 02abe2d8c9e5e33e5e31fd7fd078f7259e749585..5b6dd993484f7d1013b0d3cfe89b6a49d9e7a752 100644 --- a/tests/Aggregation/TopHitsAggregationTest.php +++ b/tests/Aggregation/TopHitsAggregationTest.php @@ -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, diff --git a/tests/Query/BoolQueryTest.php b/tests/Query/BoolQueryTest.php index 1634e765c619bd752c8db8811ec1e352a7a3d365..4505857c21c346cf57de1b392849c2d16b47f59a 100644 --- a/tests/Query/BoolQueryTest.php +++ b/tests/Query/BoolQueryTest.php @@ -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() {