1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\COG\ChronoShifter\Period; |
4
|
|
|
|
5
|
|
|
use COG\ChronoShifter\Direction\Decreasing; |
6
|
|
|
use COG\ChronoShifter\Direction\Direction; |
7
|
|
|
use COG\ChronoShifter\Direction\Increasing; |
8
|
|
|
use COG\ChronoShifter\Period\Month; |
9
|
|
|
use COG\ChronoShifter\Selector\Specific; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Kristjan Siimson <[email protected]> |
13
|
|
|
* @package Selector\Test |
14
|
|
|
*/ |
15
|
|
|
class SpecificTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
View Code Duplication |
public function testIfUpcomingMatchFoundUseCurrentPeriod() |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
$selector = new Specific(new Increasing(), 15); |
20
|
|
|
|
21
|
|
|
$date = '2014-02-05'; |
22
|
|
|
$period = new Month($date); |
23
|
|
|
$this->assertEquals('2014-02-15', $selector->select($date, $period)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
View Code Duplication |
public function testIfNoUpcomingMatchFoundUseNextPeriod() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$selector = new Specific(new Increasing(), 15); |
29
|
|
|
|
30
|
|
|
$date = '2014-02-25'; |
31
|
|
|
$period = new Month($date); |
32
|
|
|
$this->assertEquals('2014-03-15', $selector->select($date, $period)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function testIfNoUpcomingMatchFoundUsePreviousPeriod() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$selector = new Specific(new Decreasing(), 15); |
38
|
|
|
|
39
|
|
|
$date = '2014-02-05'; |
40
|
|
|
$period = new Month($date); |
41
|
|
|
$this->assertEquals('2014-01-15', $selector->select($date, $period)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function testCapNumberToDaysInPeriod() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$selector = new Specific(new Increasing(), 31); |
47
|
|
|
|
48
|
|
|
$date = '2015-02-01'; |
49
|
|
|
$period = new Month($date); |
50
|
|
|
$this->assertEquals('2015-02-28', $selector->select($date, $period)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @expectedException \InvalidArgumentException |
55
|
|
|
*/ |
56
|
|
|
public function testInvalidArgumentWillThrowException() |
57
|
|
|
{ |
58
|
|
|
new Specific($this->getMockForAbstractClass('COG\ChronoShifter\Direction\Direction'), '1.5'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @expectedException \OutOfBoundsException |
63
|
|
|
* @uses Direction |
64
|
|
|
*/ |
65
|
|
|
public function testBelowOneDayWillThrowException() |
66
|
|
|
{ |
67
|
|
|
new Specific($this->getMockForAbstractClass('COG\ChronoShifter\Direction\Direction'), 0); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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.