| @@ 11-60 (lines=50) @@ | ||
| 8 | * @author Kristjan Siimson <[email protected]> |
|
| 9 | * @package Shifter\Test |
|
| 10 | */ |
|
| 11 | 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 | ||
| @@ 11-60 (lines=50) @@ | ||
| 8 | * @author Kristjan Siimson <[email protected]> |
|
| 9 | * @package Shifter\Test |
|
| 10 | */ |
|
| 11 | class FirstMatchBeforeTest 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 | $firstMatchBeforeShifter = new FirstMatchBefore($shifter, $evaluator); |
|
| 22 | ||
| 23 | $this->assertEquals('2015-02-01', $firstMatchBeforeShifter->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 | $firstMatchBeforeShifter = new FirstMatchBefore($shifter, $evaluator); |
|
| 57 | ||
| 58 | $this->assertEquals('2015-01-30', $firstMatchBeforeShifter->shift('2011-01-01')); |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||