Skip to content
Snippets Groups Projects
Commit 80ac4773 authored by Martynas Sudintas's avatar Martynas Sudintas
Browse files

Added sub aggregations setter in AbstractAggregation

parent 1df71dc4
No related branches found
No related tags found
No related merge requests found
......@@ -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' => [
......
......@@ -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' => [
......
......@@ -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());
}
}
......@@ -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' => [
......
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