1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\COG\ChronoShifter\Shifter; |
4
|
|
|
|
5
|
|
|
use COG\ChronoShifter\Direction\Decreasing; |
6
|
|
|
use COG\ChronoShifter\Evaluator\Workday; |
7
|
|
|
use COG\ChronoShifter\HolidayProvider\ArrayHolidayProvider; |
8
|
|
|
use COG\ChronoShifter\Period\Month; |
9
|
|
|
use COG\ChronoShifter\Selector\FirstOf; |
10
|
|
|
use COG\ChronoShifter\Shifter\ChronoShifter; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Kristjan Siimson <[email protected]> |
14
|
|
|
* @package Shifter\Test |
15
|
|
|
*/ |
16
|
|
|
class MonthlyFirstWorkdayDecrementTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
private $fixture = array( |
22
|
|
|
|
23
|
|
|
// Start at one second after first workday of month, shift to previous day |
24
|
|
|
|
25
|
|
|
array( |
26
|
|
|
'2015-06-02', // Starting time |
27
|
|
|
'2015-06-01', // Expected time |
28
|
|
|
), |
29
|
|
|
|
30
|
|
|
// Start at last second of first workday of month, shift back by a month |
31
|
|
|
|
32
|
|
|
array( |
33
|
|
|
'2015-06-01', // Starting time |
34
|
|
|
'2015-05-01', // Expected time |
35
|
|
|
), |
36
|
|
|
|
37
|
|
|
// Start on day after first workday of month, Monday 3rd |
38
|
|
|
|
39
|
|
|
array( |
40
|
|
|
'2015-08-04 15:12:24', // Starting time |
41
|
|
|
'2015-08-03', // Expected time |
42
|
|
|
), |
43
|
|
|
|
44
|
|
|
// Start on first workday of month, Monday 3rd |
45
|
|
|
|
46
|
|
|
array( |
47
|
|
|
'2015-08-03', // Starting time |
48
|
|
|
'2015-07-01', // Expected time |
49
|
|
|
), |
50
|
|
|
|
51
|
|
|
array( |
52
|
|
|
'2015-04-30', // Starting time |
53
|
|
|
'2015-04-03', // Expected time |
54
|
|
|
[ |
55
|
|
|
'2015-04-01', // Holidays |
56
|
|
|
'2015-04-02' |
57
|
|
|
] |
58
|
|
|
), |
59
|
|
|
|
60
|
|
|
array( |
61
|
|
|
'2015-11-30', // Starting time |
62
|
|
|
'2015-11-04', // Expected time |
63
|
|
|
[ |
64
|
|
|
'2015-11-02', // Holidays |
65
|
|
|
'2015-11-03' |
66
|
|
|
] |
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @dataProvider shiftProvider |
72
|
|
|
* @param string $start |
73
|
|
|
* @param string $expected |
74
|
|
|
* @param string[] $holidays |
75
|
|
|
*/ |
76
|
|
|
public function testShift($start, $expected, $holidays = array()) |
77
|
|
|
{ |
78
|
|
|
$shifter = new ChronoShifter(new Month($start), |
79
|
|
|
new FirstOf(new Decreasing(), new Workday(new ArrayHolidayProvider($holidays)))); |
80
|
|
|
$result = $shifter->shift($start); |
81
|
|
|
|
82
|
|
|
$this->assertEquals( |
83
|
|
|
$expected, |
84
|
|
|
$result, |
85
|
|
|
sprintf( |
86
|
|
|
'From %s to previous first workday of month ', |
87
|
|
|
$start |
88
|
|
|
) |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
public function shiftProvider() |
96
|
|
|
{ |
97
|
|
|
return $this->fixture; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|