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