|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\COG\ChronoShifter\Shifter; |
|
4
|
|
|
|
|
5
|
|
|
use COG\ChronoShifter\Direction\Decreasing; |
|
6
|
|
|
use COG\ChronoShifter\Evaluator\DayOfWeek; |
|
7
|
|
|
use COG\ChronoShifter\Period\Month; |
|
8
|
|
|
use COG\ChronoShifter\Selector\LastOf; |
|
9
|
|
|
use COG\ChronoShifter\Shifter\ChronoShifter; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Kristjan Siimson <[email protected]> |
|
13
|
|
|
* @package Shifter\Test |
|
14
|
|
|
*/ |
|
15
|
|
|
class MonthlyLastDayOfWeekDecrementTest extends \PHPUnit_Framework_TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
private $fixture = array( |
|
21
|
|
|
|
|
22
|
|
|
array( |
|
23
|
|
|
3, // Wednesday |
|
24
|
|
|
'2015-07-01', // Starting time |
|
25
|
|
|
'2015-06-24' // Expected time |
|
26
|
|
|
), |
|
27
|
|
|
|
|
28
|
|
|
array( |
|
29
|
|
|
3, // Wednesday |
|
30
|
|
|
'2015-07-01 15:12:24', // Starting time |
|
31
|
|
|
'2015-06-24' // Expected time |
|
32
|
|
|
), |
|
33
|
|
|
|
|
34
|
|
|
array( |
|
35
|
|
|
4, // Thursday |
|
36
|
|
|
'2015-06-25 15:12:24', // Starting time |
|
37
|
|
|
'2015-05-28' // Expected time |
|
38
|
|
|
), |
|
39
|
|
|
|
|
40
|
|
|
// Day of week is also last day of month |
|
41
|
|
|
|
|
42
|
|
|
array( |
|
43
|
|
|
2, // Tuesday |
|
44
|
|
|
'2016-06-05', // Starting time |
|
45
|
|
|
'2016-05-31' // Expected time |
|
46
|
|
|
) |
|
47
|
|
|
|
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @dataProvider shiftProvider |
|
52
|
|
|
* @param integer $day |
|
53
|
|
|
* @param string $start |
|
54
|
|
|
* @param string $expected |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testShift($day, $start, $expected) |
|
57
|
|
|
{ |
|
58
|
|
|
$shifter = new ChronoShifter(new Month($start), new LastOf(new Decreasing(), new DayOfWeek($day))); |
|
59
|
|
|
$result = $shifter->shift($start); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertEquals( |
|
62
|
|
|
$expected, |
|
63
|
|
|
$result, |
|
64
|
|
|
sprintf( |
|
65
|
|
|
'From %s to previous last week day of month = %d', |
|
66
|
|
|
$start, |
|
67
|
|
|
$day |
|
68
|
|
|
) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
public function shiftProvider() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->fixture; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|