1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\COG\ChronoShifter\Shifter; |
4
|
|
|
|
5
|
|
|
use COG\ChronoShifter\Shifter\FirstMatchAfter; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Kristjan Siimson <[email protected]> |
9
|
|
|
* @package Shifter\Test |
10
|
|
|
*/ |
11
|
|
View Code Duplication |
class FirstMatchAfterShifterTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
public function testIfMatchKeepDate() |
14
|
|
|
{ |
15
|
|
|
$shifter = $this->mockShifter(); |
16
|
|
|
$shifter->expects($this->any())->method('shift')->will($this->returnValue('2015-02-01')); |
17
|
|
|
|
18
|
|
|
$evaluator = $this->mockEvaluator(); |
19
|
|
|
$evaluator->expects($this->any())->method('is')->will($this->returnValue(true)); |
20
|
|
|
|
21
|
|
|
$firstMatchAfterShifter = new FirstMatchAfter($shifter, $evaluator); |
22
|
|
|
|
23
|
|
|
$this->assertEquals('2015-02-01', $firstMatchAfterShifter->shift('2011-01-01')); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
28
|
|
|
*/ |
29
|
|
|
private function mockShifter() |
30
|
|
|
{ |
31
|
|
|
return $this |
32
|
|
|
->getMockBuilder('COG\ChronoShifter\Shifter\Shifter') |
33
|
|
|
->setMethods(array('shift')) |
34
|
|
|
->getMock(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
39
|
|
|
*/ |
40
|
|
|
private function mockEvaluator() |
41
|
|
|
{ |
42
|
|
|
return $this |
43
|
|
|
->getMockBuilder('COG\ChronoShifter\Evaluator\Evaluator') |
44
|
|
|
->setMethods(array('is')) |
45
|
|
|
->getMock(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testIfNotMatchIncrementDate() |
49
|
|
|
{ |
50
|
|
|
$shifter = $this->mockShifter(); |
51
|
|
|
$shifter->expects($this->any())->method('shift')->will($this->returnValue('2015-02-01')); |
52
|
|
|
|
53
|
|
|
$evaluator = $this->mockEvaluator(); |
54
|
|
|
$evaluator->expects($this->any())->method('is')->will($this->onConsecutiveCalls(false, false, true)); |
55
|
|
|
|
56
|
|
|
$firstMatchAfterShifter = new FirstMatchAfter($shifter, $evaluator); |
57
|
|
|
|
58
|
|
|
$this->assertEquals('2015-02-03', $firstMatchAfterShifter->shift('2011-01-01')); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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.