@@ -296,11 +296,18 @@ public function testGetDateRangeFirstPart($range, $customStart, $customEnd, $exp
296
296
* @param string $customEnd
297
297
* @param string $config
298
298
* @param string $configVal
299
+ * @param DateTime $expectedYear
299
300
* @dataProvider secondPartDateRangeDataProvider
300
301
* @return void
301
302
*/
302
- public function testGetDateRangeSecondPart ($ range , $ customStart , $ customEnd , $ config , $ configVal ): void
303
- {
303
+ public function testGetDateRangeSecondPart (
304
+ $ range ,
305
+ $ customStart ,
306
+ $ customEnd ,
307
+ $ config ,
308
+ $ configVal ,
309
+ $ expectedYear
310
+ ): void {
304
311
$ this ->scopeConfigMock
305
312
->expects ($ this ->once ())
306
313
->method ('getValue ' )
@@ -310,37 +317,10 @@ public function testGetDateRangeSecondPart($range, $customStart, $customEnd, $co
310
317
)
311
318
->willReturn ($ configVal );
312
319
313
- $ dateStart = new \DateTime ();
314
- $ dateStart ->setTime (0 , 0 , 0 );
315
-
316
- switch ($ range ) {
317
- case '1m ' :
318
- $ dateStart ->setDate (
319
- (int )$ dateStart ->format ('Y ' ),
320
- (int )$ dateStart ->format ('m ' ),
321
- (int )$ configVal
322
- );
323
- break ;
324
-
325
- case '1y ' :
326
- case '2y ' :
327
- $ startMonthDay = explode (
328
- ', ' ,
329
- $ configVal
330
- );
331
- $ startMonth = isset ($ startMonthDay [0 ]) ? (int )$ startMonthDay [0 ] : 1 ;
332
- $ startDay = isset ($ startMonthDay [1 ]) ? (int )$ startMonthDay [1 ] : 1 ;
333
- $ dateStart ->setDate ((int )$ dateStart ->format ('Y ' ), $ startMonth , $ startDay );
334
- if ($ range == '2y ' ) {
335
- $ dateStart ->modify ('-1 year ' );
336
- }
337
- break ;
338
- }
339
-
340
320
$ result = $ this ->collection ->getDateRange ($ range , $ customStart , $ customEnd );
341
321
$ this ->assertCount (3 , $ result );
342
322
$ resultStartDate = $ result ['from ' ];
343
- $ this ->assertEquals ($ dateStart -> format ( ' Y ' ) , $ resultStartDate ->format ('Y ' ));
323
+ $ this ->assertEquals ($ expectedYear , $ resultStartDate ->format ('Y ' ));
344
324
}
345
325
346
326
/**
@@ -498,10 +478,14 @@ public function firstPartDateRangeDataProvider(): array
498
478
*/
499
479
public function secondPartDateRangeDataProvider (): array
500
480
{
481
+ $ dateStart = new \DateTime ();
482
+ $ expectedYear = $ dateStart ->format ('Y ' );
483
+ $ expected2YTDYear = $ expectedYear - 1 ;
484
+
501
485
return [
502
- ['1m ' , 1 , 10 , 'reports/dashboard/mtd_start ' , '1 ' ],
503
- ['1y ' , 1 , 10 , 'reports/dashboard/ytd_start ' , '1,1 ' ],
504
- ['2y ' , 1 , 10 , 'reports/dashboard/ytd_start ' , '1,1 ' ]
486
+ ['1m ' , 1 , 10 , 'reports/dashboard/mtd_start ' , '1 ' , $ expectedYear ],
487
+ ['1y ' , 1 , 10 , 'reports/dashboard/ytd_start ' , '1,1 ' , $ expectedYear ],
488
+ ['2y ' , 1 , 10 , 'reports/dashboard/ytd_start ' , '1,1 ' , $ expected2YTDYear ]
505
489
];
506
490
}
507
491
0 commit comments