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\FirstOf; |
9
|
|
|
use COG\ChronoShifter\Shifter\ChronoShifter; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Kristjan Siimson <[email protected]> |
13
|
|
|
* @package Shifter\Test |
14
|
|
|
*/ |
15
|
|
|
class MonthlyFirstDayOfWeekDecrementTest 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-03' // Expected time |
26
|
|
|
), |
27
|
|
|
|
28
|
|
|
array( |
29
|
|
|
3, // Wednesday |
30
|
|
|
'2015-07-01 15:12:24', // Starting time |
31
|
|
|
'2015-06-03' // Expected time |
32
|
|
|
), |
33
|
|
|
|
34
|
|
|
array( |
35
|
|
|
4, // Thursday |
36
|
|
|
'2015-07-04 15:12:24', // Starting time |
37
|
|
|
'2015-07-02' // Expected time |
38
|
|
|
), |
39
|
|
|
|
40
|
|
|
// Day of week is also first day of month |
41
|
|
|
|
42
|
|
|
array( |
43
|
|
|
7, // Sunday |
44
|
|
|
'2015-02-15', // Starting time |
45
|
|
|
'2015-02-01' |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @dataProvider shiftProvider |
51
|
|
|
* @param integer $day |
52
|
|
|
* @param string $start |
53
|
|
|
* @param string $expected |
54
|
|
|
*/ |
55
|
|
|
public function testShift($day, $start, $expected) |
56
|
|
|
{ |
57
|
|
|
$shifter = new ChronoShifter(new Month($start), new FirstOf(new Decreasing(), new DayOfWeek($day))); |
58
|
|
|
$result = $shifter->shift($start); |
59
|
|
|
|
60
|
|
|
$this->assertEquals( |
61
|
|
|
$expected, |
62
|
|
|
$result, |
63
|
|
|
sprintf( |
64
|
|
|
'From %s to previous first week day of month = %d', |
65
|
|
|
$start, |
66
|
|
|
$day |
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function shiftProvider() |
75
|
|
|
{ |
76
|
|
|
return $this->fixture; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|