@@ -139,7 +139,7 @@ public function testAggregatePerStoreCalculationWithInterval(): void
139
139
->willReturn ($ periodExpr );
140
140
$ connection ->expects ($ this ->any ())->method ('select ' )->willReturn ($ select );
141
141
$ query = $ this ->createMock (\Zend_Db_Statement_Interface::class);
142
- $ connection ->expects ($ this ->exactly (3 ))->method ('query ' )->willReturn ($ query );
142
+ $ connection ->expects ($ this ->exactly (4 ))->method ('query ' )->willReturn ($ query );
143
143
$ resource = $ this ->createMock (ResourceConnection::class);
144
144
$ resource ->expects ($ this ->any ())
145
145
->method ('getConnection ' )
@@ -180,6 +180,68 @@ public function testAggregatePerStoreCalculationWithInterval(): void
180
180
$ this ->report ->aggregate ($ from , $ to );
181
181
}
182
182
183
+ public function testClearByDateRange ()
184
+ {
185
+ $ from = new \DateTime ('yesterday ' );
186
+ $ to = new \DateTime ();
187
+ $ periodExpr = 'DATE(DATE_ADD(`source_table`.`created_at`, INTERVAL -25200 SECOND)) ' ;
188
+
189
+ $ connection = $ this ->createMock (AdapterInterface::class);
190
+ $ resource = $ this ->createMock (ResourceConnection::class);
191
+ $ resource ->expects ($ this ->any ())
192
+ ->method ('getConnection ' )
193
+ ->with ($ this ->connectionName )
194
+ ->willReturn ($ connection );
195
+ $ this ->context ->expects ($ this ->any ())->method ('getResources ' )->willReturn ($ resource );
196
+
197
+ $ store = $ this ->createMock (StoreInterface::class);
198
+ $ store ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
199
+ $ this ->storeManager ->expects ($ this ->once ())->method ('getStores ' )->with (true )->willReturn ([$ store ]);
200
+
201
+ $ select = $ this ->getMockBuilder (Select::class)
202
+ ->disableOriginalConstructor ()
203
+ ->getMock ();
204
+ $ select ->expects ($ this ->atLeastOnce ())->method ('from ' )->willReturnSelf ();
205
+ $ select ->expects ($ this ->atLeastOnce ())->method ('joinInner ' )->willReturnSelf ();
206
+ $ select ->expects ($ this ->atLeastOnce ())->method ('joinLeft ' )->willReturnSelf ();
207
+ $ select ->expects ($ this ->atLeastOnce ())->method ('where ' )->willReturnSelf ();
208
+ $ select ->expects ($ this ->atLeastOnce ())->method ('distinct ' )->willReturnSelf ();
209
+ $ connection ->expects ($ this ->any ())->method ('select ' )->willReturn ($ select );
210
+
211
+ $ date = $ this ->createMock (\DateTime::class);
212
+ $ date ->expects ($ this ->atLeastOnce ())->method ('format ' )->with ('e ' );
213
+ $ this ->time ->expects ($ this ->atLeastOnce ())->method ('scopeDate ' )->willReturn ($ date );
214
+
215
+ $ flag = $ this ->createMock (Flag::class);
216
+ $ flag ->expects ($ this ->atLeastOnce ())->method ('setReportFlagCode ' )->willReturnSelf ();
217
+ $ flag ->expects ($ this ->atLeastOnce ())->method ('unsetData ' )->willReturnSelf ();
218
+ $ flag ->expects ($ this ->atLeastOnce ())->method ('loadSelf ' );
219
+ $ this ->flagFactory ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturn ($ flag );
220
+
221
+ $ query = $ this ->createMock (\Zend_Db_Statement_Interface::class);
222
+ $ query ->method ('fetchColumn ' )->willReturnOnConsecutiveCalls ('date1 ' , 'date2 ' , false );
223
+ $ connection ->expects ($ this ->atLeastOnce ())->method ('query ' )->willReturn ($ query );
224
+ $ connection ->expects ($ this ->atLeastOnce ())->method ('getDatePartSql ' )->willReturn ($ periodExpr );
225
+
226
+ $ connection ->expects ($ this ->exactly (2 ))->method ('delete ' );
227
+
228
+ $ this ->report = new Bestsellers (
229
+ $ this ->context ,
230
+ $ this ->logger ,
231
+ $ this ->time ,
232
+ $ this ->flagFactory ,
233
+ $ this ->validator ,
234
+ $ this ->date ,
235
+ $ this ->product ,
236
+ $ this ->helper ,
237
+ $ this ->connectionName ,
238
+ [],
239
+ $ this ->storeManager
240
+ );
241
+
242
+ $ this ->report ->aggregate ($ from , $ to );
243
+ }
244
+
183
245
/**
184
246
* @return void
185
247
* @throws \Exception
0 commit comments