6
6
namespace Magento \Elasticsearch \Test \Unit \SearchAdapter \Query \Builder ;
7
7
8
8
use Magento \Elasticsearch \SearchAdapter \Query \Builder \Aggregation ;
9
+ use Magento \Framework \Search \Request \BucketInterface ;
9
10
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
11
11
12
class AggregationTest extends \PHPUnit \Framework \TestCase
@@ -26,7 +27,7 @@ class AggregationTest extends \PHPUnit\Framework\TestCase
26
27
protected $ requestInterface ;
27
28
28
29
/**
29
- * @var \Magento\Framework\Search\Request\ BucketInterface|\PHPUnit_Framework_MockObject_MockObject
30
+ * @var BucketInterface|\PHPUnit_Framework_MockObject_MockObject
30
31
*/
31
32
protected $ requestBucketInterface ;
32
33
@@ -47,7 +48,7 @@ protected function setUp()
47
48
->disableOriginalConstructor ()
48
49
->getMock ();
49
50
50
- $ this ->requestBucketInterface = $ this ->getMockBuilder (\ Magento \ Framework \ Search \ Request \ BucketInterface::class)
51
+ $ this ->requestBucketInterface = $ this ->getMockBuilder (BucketInterface::class)
51
52
->disableOriginalConstructor ()
52
53
->getMock ();
53
54
@@ -139,28 +140,35 @@ public function testBuildTerm()
139
140
'type ' => 'product ' ,
140
141
'body ' => [],
141
142
];
143
+ $ bucketName = 'price_bucket ' ;
142
144
143
- $ this ->requestInterface -> expects ( $ this -> any ())
145
+ $ this ->requestInterface
144
146
->method ('getAggregation ' )
145
147
->willReturn ([$ this ->requestBucketInterface ]);
146
148
147
- $ this ->fieldMapper -> expects ( $ this -> any ())
149
+ $ this ->fieldMapper
148
150
->method ('getFieldName ' )
149
151
->willReturn ('price ' );
150
152
151
- $ this ->requestBucketInterface -> expects ( $ this -> any ())
153
+ $ this ->requestBucketInterface
152
154
->method ('getField ' )
153
155
->willReturn ('price ' );
154
156
155
- $ this ->requestBucketInterface -> expects ( $ this -> any ())
157
+ $ this ->requestBucketInterface
156
158
->method ('getType ' )
157
- ->willReturn (' termBucket ' );
159
+ ->willReturn (BucketInterface:: TYPE_TERM );
158
160
159
- $ this ->requestBucketInterface -> expects ( $ this -> any ())
161
+ $ this ->requestBucketInterface
160
162
->method ('getName ' )
161
- ->willReturn (' price_bucket ' );
163
+ ->willReturn ($ bucketName );
162
164
163
165
$ result = $ this ->model ->build ($ this ->requestInterface , $ query );
166
+
164
167
$ this ->assertNotNull ($ result );
168
+ $ this ->assertTrue (
169
+ isset ($ result ['body ' ]['aggregations ' ][$ bucketName ]['terms ' ]['size ' ]),
170
+ 'The size have to be specified since by default, ' .
171
+ 'the terms aggregation will return only the buckets for the top ten terms ordered by the doc_count '
172
+ );
165
173
}
166
174
}
0 commit comments