Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation;
use ONGR\ElasticsearchDSL\Aggregation\Bucketing\CompositeAggregation;
use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation;
class CompositeAggregationTest extends \PHPUnit\Framework\TestCase
{
/**
* Test for composite aggregation toArray() method exception.
*/
public function testToArray()
{
$compositeAgg = new CompositeAggregation('composite_test_agg');
$termsAgg = new TermsAggregation('test_term_agg', 'test_field');
$compositeAgg->addSource($termsAgg);
$expectedResult = [
'composite' => [
'sources' => [
[
'test_term_agg' => [ 'terms' => ['field' => 'test_field'] ],
]
]
],
];
$this->assertEquals($expectedResult, $compositeAgg->toArray());
}
/**
* Tests getType method.
*/
public function testGetType()
{
$aggregation = new CompositeAggregation('foo');
$result = $aggregation->getType();
$this->assertEquals('composite', $result);
}
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
public function testTermsSourceWithOrderParameter()
{
$compositeAgg = new CompositeAggregation('composite_with_order');
$termsAgg = new TermsAggregation('test_term_agg', 'test_field');
$termsAgg->addParameter('order', 'asc');
$compositeAgg->addSource($termsAgg);
$expectedResult = [
'composite' => [
'sources' => [
[
'test_term_agg' => [ 'terms' => ['field' => 'test_field', 'order' => 'asc'] ],
]
]
],
];
$this->assertEquals($expectedResult, $compositeAgg->toArray());
}
public function testTermsSourceWithDescOrderParameter()
{
$compositeAgg = new CompositeAggregation('composite_with_order');
$termsAgg = new TermsAggregation('test_term_agg', 'test_field');
$termsAgg->addParameter('order', 'desc');
$compositeAgg->addSource($termsAgg);
$expectedResult = [
'composite' => [
'sources' => [
[
'test_term_agg' => [ 'terms' => ['field' => 'test_field', 'order' => 'desc'] ],
]
]
],
];
$this->assertEquals($expectedResult, $compositeAgg->toArray());
}
public function testMultipleSourcesWithDifferentOrders()
{
$compositeAgg = new CompositeAggregation('composite_with_order');
$termsAgg = new TermsAggregation('test_term_agg_1', 'test_field');
$termsAgg->addParameter('order', 'desc');
$compositeAgg->addSource($termsAgg);
$termsAgg = new TermsAggregation('test_term_agg_2', 'test_field');
$termsAgg->addParameter('order', 'asc');
$compositeAgg->addSource($termsAgg);
$expectedResult = [
'composite' => [
'sources' => [
[
'test_term_agg_1' => [ 'terms' => ['field' => 'test_field', 'order' => 'desc'] ],
],
[
'test_term_agg_2' => [ 'terms' => ['field' => 'test_field', 'order' => 'asc'] ],
]
]
],
];
$this->assertEquals($expectedResult, $compositeAgg->toArray());
}