1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\COG\ChronoShifter\Period; |
4
|
|
|
|
5
|
|
|
use COG\ChronoShifter\Period\Month; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Kristjan Siimson <[email protected]> |
9
|
|
|
* @package Period\Test |
10
|
|
|
*/ |
11
|
|
|
class MonthTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @dataProvider createMonthByAnyDateInRangeProvider |
15
|
|
|
* @param string $date |
16
|
|
|
* @param string $startDate |
17
|
|
|
* @param string $endDate |
18
|
|
|
*/ |
19
|
|
|
public function testCreateMonthByAnyDateInRange($date, $startDate, $endDate) |
20
|
|
|
{ |
21
|
|
|
$month = new Month($date); |
22
|
|
|
|
23
|
|
|
$this->assertEquals($startDate, $month->getStartDate()); |
24
|
|
|
$this->assertEquals($endDate, $month->getEndDate()); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
public function createMonthByAnyDateInRangeProvider() |
31
|
|
|
{ |
32
|
|
|
return array( |
33
|
|
|
array('1999-12-31', '1999-12-01', '1999-12-31'), |
34
|
|
|
array('2000-01-01', '2000-01-01', '2000-01-31'), |
35
|
|
|
array('2000-02-15', '2000-02-01', '2000-02-29') |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider nextMonthProvider |
41
|
|
|
* @param string $date |
42
|
|
|
* @param string $startDate |
43
|
|
|
* @param string $endDate |
44
|
|
|
*/ |
45
|
|
|
public function testNextMonth($date, $startDate, $endDate) |
46
|
|
|
{ |
47
|
|
|
$month = new Month($date); |
48
|
|
|
$month->next(); |
49
|
|
|
|
50
|
|
|
$this->assertEquals($startDate, $month->getStartDate()); |
51
|
|
|
$this->assertEquals($endDate, $month->getEndDate()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
public function nextMonthProvider() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
return array( |
60
|
|
|
array('1999-11-30', '1999-12-01', '1999-12-31'), |
61
|
|
|
array('1999-12-31', '2000-01-01', '2000-01-31'), |
62
|
|
|
array('2000-01-15', '2000-02-01', '2000-02-29'), |
63
|
|
|
array('2000-02-01', '2000-03-01', '2000-03-31'), |
64
|
|
|
array('2000-03-01', '2000-04-01', '2000-04-30'), |
65
|
|
|
array('2000-04-01', '2000-05-01', '2000-05-31'), |
66
|
|
|
array('2000-05-01', '2000-06-01', '2000-06-30'), |
67
|
|
|
array('2000-06-01', '2000-07-01', '2000-07-31'), |
68
|
|
|
array('2000-07-01', '2000-08-01', '2000-08-31'), |
69
|
|
|
array('2000-08-01', '2000-09-01', '2000-09-30'), |
70
|
|
|
array('2000-09-01', '2000-10-01', '2000-10-31'), |
71
|
|
|
array('2000-10-01', '2000-11-01', '2000-11-30'), |
72
|
|
|
array('2000-11-01', '2000-12-01', '2000-12-31'), |
73
|
|
|
array('2000-12-01', '2001-01-01', '2001-01-31'), |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @dataProvider previousMonthProvider |
79
|
|
|
* @param string $date |
80
|
|
|
* @param string $startDate |
81
|
|
|
* @param string $endDate |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function testPreviousMonth($date, $startDate, $endDate) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$month = new Month($date); |
86
|
|
|
$month->previous(); |
87
|
|
|
|
88
|
|
|
$this->assertEquals($startDate, $month->getStartDate()); |
89
|
|
|
$this->assertEquals($endDate, $month->getEndDate()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
View Code Duplication |
public function previousMonthProvider() |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
return array( |
98
|
|
|
array('1999-11-30', '1999-10-01', '1999-10-31'), |
99
|
|
|
array('1999-12-31', '1999-11-01', '1999-11-30'), |
100
|
|
|
array('2000-01-15', '1999-12-01', '1999-12-31'), |
101
|
|
|
array('2000-02-01', '2000-01-01', '2000-01-31'), |
102
|
|
|
array('2000-03-01', '2000-02-01', '2000-02-29'), |
103
|
|
|
array('2000-04-01', '2000-03-01', '2000-03-31'), |
104
|
|
|
array('2000-05-01', '2000-04-01', '2000-04-30'), |
105
|
|
|
array('2000-06-01', '2000-05-01', '2000-05-31'), |
106
|
|
|
array('2000-07-01', '2000-06-01', '2000-06-30'), |
107
|
|
|
array('2000-08-01', '2000-07-01', '2000-07-31'), |
108
|
|
|
array('2000-09-01', '2000-08-01', '2000-08-31'), |
109
|
|
|
array('2000-10-01', '2000-09-01', '2000-09-30'), |
110
|
|
|
array('2000-11-01', '2000-10-01', '2000-10-31'), |
111
|
|
|
array('2000-12-01', '2000-11-01', '2000-11-30') |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testGetNumberOfDays() |
116
|
|
|
{ |
117
|
|
|
$month = new Month('2015-02-15'); |
118
|
|
|
$this->assertEquals(27, $month->getNumberOfDays()); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.