1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DavisPeixoto\ReportDates\Tests; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use DateTimeZone; |
7
|
|
|
use DavisPeixoto\ReportDates\DatesConfig; |
8
|
|
|
use DavisPeixoto\ReportDates\WeekInterval; |
9
|
|
|
use DavisPeixoto\ReportDates\DayNumber; |
10
|
|
|
use Exception; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
class WeekIntervalTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param DateTime $startDate |
17
|
|
|
* @param DateTime $endDate |
18
|
|
|
* @param DatesConfig $config |
19
|
|
|
* @param integer $expectedBusinessDays |
20
|
|
|
* @param integer $expectedTotalDays |
21
|
|
|
* |
22
|
|
|
* @dataProvider constructorProvider |
23
|
|
|
*/ |
24
|
|
|
public function testConstructor($startDate, $endDate, $config, $expectedBusinessDays, $expectedTotalDays) |
25
|
|
|
{ |
26
|
|
|
$weekInterval = new WeekInterval($startDate, $endDate, $config); |
27
|
|
|
$this->assertEquals($expectedBusinessDays, $weekInterval->getBusinessDays()); |
28
|
|
|
$this->assertEquals($expectedTotalDays, $weekInterval->getTotalDays()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return array |
|
|
|
|
33
|
|
|
* @throws Exception |
34
|
|
|
*/ |
35
|
|
|
public function constructorProvider() |
36
|
|
|
{ |
37
|
|
|
$start01 = new DateTime('2019-01-06'); |
38
|
|
|
$start02 = new DateTime('2019-01-07'); |
39
|
|
|
$start03 = new DateTime('2019-01-07'); |
40
|
|
|
$start04 = new DateTime('2019-01-01'); |
41
|
|
|
$start05 = new DateTime('2019-01-27'); |
42
|
|
|
|
43
|
|
|
$end01 = new DateTime('2019-01-12'); |
44
|
|
|
$end02 = new DateTime('2019-01-11'); |
45
|
|
|
$end03 = new DateTime('2019-01-13'); |
46
|
|
|
$end04 = new DateTime('2019-01-05'); |
47
|
|
|
$end05 = new DateTime('2019-01-31'); |
48
|
|
|
|
49
|
|
|
$expectedDays01 = 5; |
50
|
|
|
$expectedDays02 = 7; |
51
|
|
|
$expectedDays03 = 6; |
52
|
|
|
$expectedDays04 = 3; |
53
|
|
|
$expectedDays05 = 4; |
54
|
|
|
|
55
|
|
|
$configDays01 = [ |
56
|
|
|
new DayNumber(DayNumber::MONDAY), |
57
|
|
|
new DayNumber(DayNumber::TUESDAY), |
58
|
|
|
new DayNumber(DayNumber::WEDNESDAY), |
59
|
|
|
new DayNumber(DayNumber::THURSDAY), |
60
|
|
|
new DayNumber(DayNumber::FRIDAY) |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
$configDays02 = [ |
64
|
|
|
new DayNumber(DayNumber::TUESDAY), |
65
|
|
|
new DayNumber(DayNumber::WEDNESDAY), |
66
|
|
|
new DayNumber(DayNumber::THURSDAY) |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
$configDays03 = [ |
70
|
|
|
new DayNumber(DayNumber::MONDAY), |
71
|
|
|
new DayNumber(DayNumber::TUESDAY), |
72
|
|
|
new DayNumber(DayNumber::WEDNESDAY), |
73
|
|
|
new DayNumber(DayNumber::THURSDAY), |
74
|
|
|
new DayNumber(DayNumber::FRIDAY), |
75
|
|
|
new DayNumber(DayNumber::SATURDAY) |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
$tz01 = new DateTimeZone('UTC'); |
79
|
|
|
$tz02 = new DateTimeZone('America/Sao_Paulo'); |
80
|
|
|
|
81
|
|
|
$config01 = new DatesConfig($tz01, new DayNumber(DayNumber::SUNDAY), $configDays01); |
82
|
|
|
$config02 = new DatesConfig($tz01, new DayNumber(DayNumber::SUNDAY), $configDays02); |
83
|
|
|
$config03 = new DatesConfig($tz01, new DayNumber(DayNumber::SUNDAY), $configDays03); |
84
|
|
|
$config04 = new DatesConfig($tz02, new DayNumber(DayNumber::SUNDAY), $configDays01); |
85
|
|
|
|
86
|
|
|
return [ |
87
|
|
|
[$start01, $end01, $config01, $expectedDays01, $expectedDays02], |
88
|
|
|
[$start02, $end02, $config02, $expectedDays04, $expectedDays01], |
89
|
|
|
[$start03, $end03, $config03, $expectedDays03, $expectedDays02], |
90
|
|
|
[$start01, $end01, $config04, $expectedDays01, $expectedDays02], |
91
|
|
|
[$start04, $end04, $config01, $expectedDays05, $expectedDays01], |
92
|
|
|
[$start05, $end05, $config01, $expectedDays05, $expectedDays01] |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.