1
|
|
|
<?php |
2
|
|
|
namespace Tests; |
3
|
|
|
|
4
|
|
|
use BusinessDays\Calculator; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class CalculatorTest |
9
|
|
|
* |
10
|
|
|
* @package Tests |
11
|
|
|
*/ |
12
|
|
|
class CalculatorTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** @var Calculator */ |
15
|
|
|
private $_sut; |
16
|
|
|
|
17
|
|
|
public function setUp() |
18
|
|
|
{ |
19
|
|
|
$this->_sut = new Calculator(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return array |
24
|
|
|
*/ |
25
|
|
|
public function dataProvider() |
26
|
|
|
{ |
27
|
|
|
return include __DIR__ . '/fixtures/business_days.php'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @dataProvider dataProvider |
32
|
|
|
* |
33
|
|
|
* @param string $message |
34
|
|
|
* @param \DateTime $startDate |
35
|
|
|
* @param int $howManyDays |
36
|
|
|
* @param \DateTime $expected |
37
|
|
|
* @param int[] $nonBusinessDays |
38
|
|
|
* @param \DateTime[] $freeDays |
39
|
|
|
* @param \DateTime[] $holidays |
40
|
|
|
*/ |
41
|
|
|
public function testReturnsExpected( |
42
|
|
|
$message, |
43
|
|
|
\DateTime $startDate, |
44
|
|
|
$howManyDays, |
45
|
|
|
\DateTime $expected, |
46
|
|
|
array $nonBusinessDays = array(), |
47
|
|
|
array $freeDays = array(), |
48
|
|
|
array $holidays = array() |
49
|
|
|
) { |
50
|
|
|
$this->_sut->setFreeDays($freeDays); |
51
|
|
|
$this->_sut->setHolidays($holidays); |
52
|
|
|
$this->_sut->setFreeWeekDays($nonBusinessDays); |
53
|
|
|
|
54
|
|
|
$response = $this->_sut->addBusinessDays($startDate, $howManyDays); |
55
|
|
|
|
56
|
|
|
$this->assertEquals($response, $expected, $message); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @expectedException \InvalidArgumentException |
61
|
|
|
*/ |
62
|
|
|
public function testTooManyBusinessDaysException() |
63
|
|
|
{ |
64
|
|
|
$date = new \DateTime('2000-01-01'); |
65
|
|
|
|
66
|
|
|
$nonBusinessDays = [ |
67
|
|
|
Calculator::MONDAY, |
68
|
|
|
Calculator::TUESDAY, |
69
|
|
|
Calculator::WEDNESDAY, |
70
|
|
|
Calculator::THURSDAY, |
71
|
|
|
Calculator::FRIDAY, |
72
|
|
|
Calculator::SATURDAY, |
73
|
|
|
Calculator::SUNDAY |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
$this->_sut->setFreeWeekDays($nonBusinessDays); |
77
|
|
|
$this->_sut->addBusinessDays($date, 1); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testThatPassedParameterIsNotChangedByReferenceInSut() |
81
|
|
|
{ |
82
|
|
|
$date = new \DateTime('2000-01-01'); |
83
|
|
|
|
84
|
|
|
$responseDate = $this->_sut->addBusinessDays($date, 1); |
85
|
|
|
|
86
|
|
|
$this->assertNotEquals($date, $responseDate); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|