1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\COG\Iterator\ChronoIterator; |
4
|
|
|
|
5
|
|
|
use COG\ChronoShifter\Shifter\ChronoShifter; |
6
|
|
|
use COG\ChronoShifter\Direction\Increasing; |
7
|
|
|
use COG\ChronoShifter\Period\IsoChronic; |
8
|
|
|
use COG\ChronoShifter\Selector\Specific; |
9
|
|
|
use COG\ChronoShifter\Iterator\ChronoIterator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Kristjan Siimson <[email protected]> |
13
|
|
|
* @package Test |
14
|
|
|
*/ |
15
|
|
|
class ChronoShifterTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
public function testChronoShifterImplementsIterator() |
18
|
|
|
{ |
19
|
|
|
$shifter = $this->createIsoChronicIncrement(); |
20
|
|
|
$iterator = new ChronoIterator($shifter, '2015-01-03'); |
21
|
|
|
|
22
|
|
|
$this->assertInstanceOf('\Iterator', $iterator); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
View Code Duplication |
public function testShifterBeginsFromFirstMatch() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$shifter = $this->createIsoChronicIncrement(); |
28
|
|
|
|
29
|
|
|
$iterator = new ChronoIterator($shifter, '2015-01-03'); |
30
|
|
|
$result = $iterator->current(); |
31
|
|
|
|
32
|
|
|
$this->assertEquals('2015-01-15', $result); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function testShifterIncrementsWithShifter() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$shifter = $this->createIsoChronicIncrement(); |
38
|
|
|
|
39
|
|
|
$iterator = new ChronoIterator($shifter, '2015-01-03'); |
40
|
|
|
$iterator->next(); |
41
|
|
|
$result = $iterator->current(); |
42
|
|
|
|
43
|
|
|
$this->assertEquals('2015-01-29', $result); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testShifterKeyIsTimestamp() |
47
|
|
|
{ |
48
|
|
|
$shifter = $this->createIsoChronicIncrement(); |
49
|
|
|
|
50
|
|
|
$iterator = new ChronoIterator($shifter, '2015-01-03'); |
51
|
|
|
$iterator->next(); |
52
|
|
|
|
53
|
|
|
$date = new \DateTime(); |
54
|
|
|
$date->setTimezone(new \DateTimeZone('Europe/Helsinki')); |
55
|
|
|
$date->setDate(2015, 01, 15)->setTime(0, 0, 0); |
56
|
|
|
|
57
|
|
|
$this->assertInternalType('integer', $iterator->key()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testShifterPositionValidForOldDates() |
61
|
|
|
{ |
62
|
|
|
$shifter = $this->createIsoChronicIncrement(); |
63
|
|
|
$iterator = new ChronoIterator($shifter, '1988-09-01'); |
64
|
|
|
|
65
|
|
|
$this->assertTrue($iterator->valid()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testShifterPositionValidForFutureDates() |
69
|
|
|
{ |
70
|
|
|
$shifter = $this->createIsoChronicIncrement(); |
71
|
|
|
$iterator = new ChronoIterator($shifter, '2100-09-01'); |
72
|
|
|
|
73
|
|
|
$this->assertTrue($iterator->valid()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return ChronoShifter |
78
|
|
|
*/ |
79
|
|
|
private function createIsoChronicIncrement() |
80
|
|
|
{ |
81
|
|
|
return new ChronoShifter(new Isochronic('2015-01-01', '2015-01-01', 14), new Specific(new Increasing(), 1)); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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.