From 80ac47736503066998bdac82eceeead06cc352d0 Mon Sep 17 00:00:00 2001 From: Martynas Sudintas <martynas.sudintas@nfq.lt> Date: Wed, 28 Jan 2015 11:25:00 +0200 Subject: [PATCH] Added sub aggregations setter in AbstractAggregation --- Aggregation/FilterAggregationTest.php | 2 +- Aggregation/GlobalAggregationTest.php | 2 +- Aggregation/NestedAggregationTest.php | 37 +++++++++++++++++++++++++-- Aggregation/RangeAggregationTest.php | 2 +- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Aggregation/FilterAggregationTest.php b/Aggregation/FilterAggregationTest.php index 745869b..0b45a48 100644 --- a/Aggregation/FilterAggregationTest.php +++ b/Aggregation/FilterAggregationTest.php @@ -69,7 +69,7 @@ class FilterAggregationTest extends \PHPUnit_Framework_TestCase ->method('getName') ->willReturn('agg_test_agg2'); - $aggregation->aggregations->add($aggregation2); + $aggregation->addAggregation($aggregation2); $result = [ 'agg_test_agg' => [ diff --git a/Aggregation/GlobalAggregationTest.php b/Aggregation/GlobalAggregationTest.php index 1f64af0..127e7f5 100644 --- a/Aggregation/GlobalAggregationTest.php +++ b/Aggregation/GlobalAggregationTest.php @@ -41,7 +41,7 @@ class GlobalAggregationTest extends \PHPUnit_Framework_TestCase // Case #1 nested global aggregation. $aggregation = new GlobalAggregation('test_agg'); $aggregation2 = new GlobalAggregation('test_agg_2'); - $aggregation->aggregations->add($aggregation2); + $aggregation->addAggregation($aggregation2); $result = [ 'agg_test_agg' => [ diff --git a/Aggregation/NestedAggregationTest.php b/Aggregation/NestedAggregationTest.php index 98b9379..500ccb5 100644 --- a/Aggregation/NestedAggregationTest.php +++ b/Aggregation/NestedAggregationTest.php @@ -16,9 +16,11 @@ use ONGR\ElasticsearchBundle\DSL\Aggregation\NestedAggregation; class NestedAggregationTest extends \PHPUnit_Framework_TestCase { /** - * Test for nested aggregation toArray() method. + * Test for nested aggregation toArray() method exception. + * + * @expectedException \LogicException */ - public function testToArray() + public function testToArrayException() { $aggregation = new NestedAggregation('test_agg'); $aggregation->setPath('test_path'); @@ -31,4 +33,35 @@ class NestedAggregationTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedResult, $aggregation->toArray()); } + + /** + * Test for nested aggregation toArray() method exception. + */ + public function testToArray() + { + $termMock = $this + ->getMockBuilder('ONGR\ElasticsearchBundle\DSL\Aggregation\TermsAggregation') + ->disableOriginalConstructor() + ->getMock(); + + $termMock + ->expects($this->once()) + ->method('toArray') + ->will($this->returnValue(['terms' => []])); + + $aggregation = new NestedAggregation('test_nested_agg'); + $aggregation->setPath('test_path'); + $aggregation->addAggregation($termMock); + + $expectedResult = [ + 'agg_test_nested_agg' => [ + 'nested' => ['path' => 'test_path'], + 'aggregations' => [ + 'terms' => [], + ], + ], + ]; + + $this->assertEquals($expectedResult, $aggregation->toArray()); + } } diff --git a/Aggregation/RangeAggregationTest.php b/Aggregation/RangeAggregationTest.php index 0114009..6306bba 100644 --- a/Aggregation/RangeAggregationTest.php +++ b/Aggregation/RangeAggregationTest.php @@ -88,7 +88,7 @@ class RangeAggregationTest extends \PHPUnit_Framework_TestCase $aggregation2 = new RangeAggregation('test_agg_2'); $aggregation2->addRange('20', '20'); - $aggregation->aggregations->add($aggregation2); + $aggregation->addAggregation($aggregation2); $result = [ 'agg_test_agg' => [ -- GitLab