diff --git a/Aggregation/FilterAggregationTest.php b/Aggregation/FilterAggregationTest.php index 745869bd083c2fd0b6e0215c90886683fa6b7f1a..0b45a48ae0951482ddb2e4317a22cb8d4e0040cf 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 1f64af05e3897eb6976f221c09f2b867b6cb7d15..127e7f56e3a675fa16713095272e83b3c47d000f 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 98b937993352481bb1ce07a2d4d3de6d6af4a5c9..500ccb54259ac659e7c9386465ba124db08ec2ec 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 01140097ecc0448959c222b93e49ad8597ac136e..6306bba4d753a002ea87da8664440fe4b70d1f8c 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' => [