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