Passed
Push — master ( 4767ee...021155 )
by Davis
02:15
created

WeekIntervalTest::constructorProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 8.8727
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace DavisPeixoto\ReportDates\Tests;
4
5
use DateTime;
6
use DateTimeZone;
7
use DavisPeixoto\ReportDates\DatesConfig;
8
use DavisPeixoto\ReportDates\WeekInterval;
9
use DavisPeixoto\ReportDates\DayNumber;
10
use Exception;
11
use PHPUnit\Framework\TestCase;
12
13
class WeekIntervalTest extends TestCase
14
{
15
    /**
16
     * @param DateTime $startDate
17
     * @param DateTime $endDate
18
     * @param DatesConfig $config
19
     * @param integer $expectedBusinessDays
20
     * @param integer $expectedTotalDays
21
     *
22
     * @dataProvider constructorProvider
23
     */
24
    public function testConstructor($startDate, $endDate, $config, $expectedBusinessDays, $expectedTotalDays)
25
    {
26
        $weekInterval = new WeekInterval($startDate, $endDate, $config);
27
        $this->assertEquals($expectedBusinessDays, $weekInterval->getBusinessDays());
28
        $this->assertEquals($expectedTotalDays, $weekInterval->getTotalDays());
29
    }
30
31
    /**
32
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<DateTime|DatesConfig|integer>[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
33
     * @throws Exception
34
     */
35
    public function constructorProvider()
36
    {
37
        $start01 = new DateTime('2019-01-06');
38
        $start02 = new DateTime('2019-01-07');
39
        $start03 = new DateTime('2019-01-07');
40
        $start04 = new DateTime('2019-01-01');
41
        $start05 = new DateTime('2019-01-27');
42
43
        $end01 = new DateTime('2019-01-12');
44
        $end02 = new DateTime('2019-01-11');
45
        $end03 = new DateTime('2019-01-13');
46
        $end04 = new DateTime('2019-01-05');
47
        $end05 = new DateTime('2019-01-31');
48
49
        $expectedDays01 = 5;
50
        $expectedDays02 = 7;
51
        $expectedDays03 = 6;
52
        $expectedDays04 = 3;
53
        $expectedDays05 = 4;
54
55
        $configDays01 = [
56
            new DayNumber(DayNumber::MONDAY),
57
            new DayNumber(DayNumber::TUESDAY),
58
            new DayNumber(DayNumber::WEDNESDAY),
59
            new DayNumber(DayNumber::THURSDAY),
60
            new DayNumber(DayNumber::FRIDAY)
61
        ];
62
63
        $configDays02 = [
64
            new DayNumber(DayNumber::TUESDAY),
65
            new DayNumber(DayNumber::WEDNESDAY),
66
            new DayNumber(DayNumber::THURSDAY)
67
        ];
68
69
        $configDays03 = [
70
            new DayNumber(DayNumber::MONDAY),
71
            new DayNumber(DayNumber::TUESDAY),
72
            new DayNumber(DayNumber::WEDNESDAY),
73
            new DayNumber(DayNumber::THURSDAY),
74
            new DayNumber(DayNumber::FRIDAY),
75
            new DayNumber(DayNumber::SATURDAY)
76
        ];
77
78
        $tz01 = new DateTimeZone('UTC');
79
        $tz02 = new DateTimeZone('America/Sao_Paulo');
80
81
        $config01 = new DatesConfig($tz01, new DayNumber(DayNumber::SUNDAY), $configDays01);
82
        $config02 = new DatesConfig($tz01, new DayNumber(DayNumber::SUNDAY), $configDays02);
83
        $config03 = new DatesConfig($tz01, new DayNumber(DayNumber::SUNDAY), $configDays03);
84
        $config04 = new DatesConfig($tz02, new DayNumber(DayNumber::SUNDAY), $configDays01);
85
86
        return [
87
            [$start01, $end01, $config01, $expectedDays01, $expectedDays02],
88
            [$start02, $end02, $config02, $expectedDays04, $expectedDays01],
89
            [$start03, $end03, $config03, $expectedDays03, $expectedDays02],
90
            [$start01, $end01, $config04, $expectedDays01, $expectedDays02],
91
            [$start04, $end04, $config01, $expectedDays05, $expectedDays01],
92
            [$start05, $end05, $config01, $expectedDays05, $expectedDays01]
93
        ];
94
    }
95
}
96