1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\COG\ChronoShifter\Period; |
4
|
|
|
use COG\ChronoShifter\Period\IsoChronic; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @author Kristjan Siimson <[email protected]> |
8
|
|
|
* @package Period\Test |
9
|
|
|
*/ |
10
|
|
|
class IsoChronicTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @dataProvider isoChronicBoundaryProvider |
14
|
|
|
* @param string $date |
15
|
|
|
* @param string $referenceDate |
16
|
|
|
* @param int $length |
17
|
|
|
* @param string $startDate |
18
|
|
|
* @param string $endDate |
19
|
|
|
*/ |
20
|
|
|
public function testIsoChronicBoundaries($date, $referenceDate, $length, $startDate, $endDate) |
21
|
|
|
{ |
22
|
|
|
$isoChronic = new IsoChronic($date, $referenceDate, $length); |
23
|
|
|
$this->assertEquals($startDate, $isoChronic->getStartDate()); |
24
|
|
|
$this->assertEquals($endDate, $isoChronic->getEndDate()); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function isoChronicBoundaryProvider() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
return array( |
30
|
|
|
array('2014-01-03', '2014-01-01', 2, '2014-01-03', '2014-01-04'), |
31
|
|
|
array('2014-01-02', '2014-01-01', 2, '2014-01-01', '2014-01-02'), |
32
|
|
|
array('2014-01-01', '2014-01-01', 2, '2014-01-01', '2014-01-02'), |
33
|
|
|
array('2013-12-31', '2014-01-01', 2, '2013-12-30', '2013-12-31'), |
34
|
|
|
array('2013-12-30', '2014-01-01', 2, '2013-12-30', '2013-12-31'), |
35
|
|
|
array('2013-12-29', '2014-01-01', 2, '2013-12-28', '2013-12-29') |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider isoChronicIncreaseProvider |
41
|
|
|
* @param string $date |
42
|
|
|
* @param string $referenceDate |
43
|
|
|
* @param int $length |
44
|
|
|
* @param string $startDate |
45
|
|
|
* @param string $endDate |
46
|
|
|
*/ |
47
|
|
|
public function testIsoChronicIncrease($date, $referenceDate, $length, $startDate, $endDate) |
48
|
|
|
{ |
49
|
|
|
$isoChronic = new IsoChronic($date, $referenceDate, $length); |
50
|
|
|
$isoChronic->next(); |
51
|
|
|
$this->assertEquals($startDate, $isoChronic->getStartDate()); |
52
|
|
|
$this->assertEquals($endDate, $isoChronic->getEndDate()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function isoChronicIncreaseProvider() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
return array( |
58
|
|
|
array('2014-01-03', '2014-01-01', 2, '2014-01-05', '2014-01-06'), |
59
|
|
|
array('2014-01-02', '2014-01-01', 2, '2014-01-03', '2014-01-04'), |
60
|
|
|
array('2014-01-01', '2014-01-01', 2, '2014-01-03', '2014-01-04'), |
61
|
|
|
array('2013-12-31', '2014-01-01', 2, '2014-01-01', '2014-01-02'), |
62
|
|
|
array('2013-12-30', '2014-01-01', 2, '2014-01-01', '2014-01-02'), |
63
|
|
|
array('2013-12-29', '2014-01-01', 2, '2013-12-30', '2013-12-31') |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @dataProvider isoChronicDecreaseProvider |
69
|
|
|
* @param string $date |
70
|
|
|
* @param string $referenceDate |
71
|
|
|
* @param int $length |
72
|
|
|
* @param string $startDate |
73
|
|
|
* @param string $endDate |
74
|
|
|
*/ |
75
|
|
View Code Duplication |
public function testIsoChronicDecrease($date, $referenceDate, $length, $startDate, $endDate) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$isoChronic = new IsoChronic($date, $referenceDate, $length); |
78
|
|
|
$isoChronic->previous(); |
79
|
|
|
$this->assertEquals($startDate, $isoChronic->getStartDate()); |
80
|
|
|
$this->assertEquals($endDate, $isoChronic->getEndDate()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
View Code Duplication |
public function isoChronicDecreaseProvider() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
return array( |
86
|
|
|
array('2014-01-03', '2014-01-01', 2, '2014-01-01', '2014-01-02'), |
87
|
|
|
array('2014-01-02', '2014-01-01', 2, '2013-12-30', '2013-12-31'), |
88
|
|
|
array('2014-01-01', '2014-01-01', 2, '2013-12-30', '2013-12-31'), |
89
|
|
|
array('2013-12-31', '2014-01-01', 2, '2013-12-28', '2013-12-29'), |
90
|
|
|
array('2013-12-30', '2014-01-01', 2, '2013-12-28', '2013-12-29'), |
91
|
|
|
array('2013-12-29', '2014-01-01', 2, '2013-12-26', '2013-12-27') |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
} |
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.