CalculatorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 77
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A dataProvider() 0 4 1
A testReturnsExpected() 0 17 1
A testTooManyBusinessDaysException() 0 17 1
A testThatPassedParameterIsNotChangedByReferenceInSut() 0 8 1
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