TestOfMonthWeeksBuild   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 23
dl 0
loc 63
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSelection() 0 16 4
A testSize() 0 4 1
A __construct() 0 3 1
A testFetch() 0 8 2
A testEmptyDaysBefore_AfterAdjust() 0 6 2
1
<?php
2
3
require_once __DIR__ . '/simple_include.php';
4
require_once __DIR__ . '/calendar_include.php';
5
6
require_once __DIR__ . '/./calendar_test.php';
7
8
/**
9
 * Class TestOfMonthWeeks.
10
 */
11
class TestOfMonthWeeks extends TestOfCalendar
12
{
13
    /**
14
     * TestOfMonthWeeks constructor.
15
     */
16
    public function __construct()
17
    {
18
        $this->UnitTestCase('Test of Month Weeks');
19
    }
20
21
    public function setUp()
22
    {
23
        $this->cal = new Calendar_Month_Weeks(2003, 10);
24
    }
25
26
    public function testPrevDay()
27
    {
28
        $this->assertEqual(30, $this->cal->prevDay());
29
    }
30
31
    public function testPrevDay_Array()
32
    {
33
        $this->assertEqual([
34
                               'year'   => 2003,
35
                               'month'  => 9,
36
                               'day'    => 30,
37
                               'hour'   => 0,
38
                               'minute' => 0,
39
                               'second' => 0,
40
                           ], $this->cal->prevDay('array'));
41
    }
42
43
    public function testThisDay()
44
    {
45
        $this->assertEqual(1, $this->cal->thisDay());
46
    }
47
48
    public function testNextDay()
49
    {
50
        $this->assertEqual(2, $this->cal->nextDay());
51
    }
52
53
    public function testPrevHour()
54
    {
55
        $this->assertEqual(23, $this->cal->prevHour());
56
    }
57
58
    public function testThisHour()
59
    {
60
        $this->assertEqual(0, $this->cal->thisHour());
61
    }
62
63
    public function testNextHour()
64
    {
65
        $this->assertEqual(1, $this->cal->nextHour());
66
    }
67
68
    public function testPrevMinute()
69
    {
70
        $this->assertEqual(59, $this->cal->prevMinute());
71
    }
72
73
    public function testThisMinute()
74
    {
75
        $this->assertEqual(0, $this->cal->thisMinute());
76
    }
77
78
    public function testNextMinute()
79
    {
80
        $this->assertEqual(1, $this->cal->nextMinute());
81
    }
82
83
    public function testPrevSecond()
84
    {
85
        $this->assertEqual(59, $this->cal->prevSecond());
86
    }
87
88
    public function testThisSecond()
89
    {
90
        $this->assertEqual(0, $this->cal->thisSecond());
91
    }
92
93
    public function testNextSecond()
94
    {
95
        $this->assertEqual(1, $this->cal->nextSecond());
96
    }
97
98
    public function testGetTimeStamp()
99
    {
100
        $stamp = mktime(0, 0, 0, 10, 1, 2003);
101
        $this->assertEqual($stamp, $this->cal->getTimestamp());
102
    }
103
}
104
105
/**
106
 * Class TestOfMonthWeeksBuild.
107
 */
108
class TestOfMonthWeeksBuild extends TestOfMonthWeeks
109
{
110
    /**
111
     * TestOfMonthWeeksBuild constructor.
112
     */
113
    public function __construct()
114
    {
115
        $this->UnitTestCase('Test of Month_Weeks::build()');
116
    }
117
118
    public function testSize()
119
    {
120
        $this->cal->build();
121
        $this->assertEqual(5, $this->cal->size());
122
    }
123
124
    public function testFetch()
125
    {
126
        $this->cal->build();
127
        $i = 0;
128
        while ($Child = $this->cal->fetch()) {
0 ignored issues
show
Unused Code introduced by
The assignment to $Child is dead and can be removed.
Loading history...
129
            ++$i;
130
        }
131
        $this->assertEqual(5, $i);
132
    }
133
134
    /* Recusive dependency issue with SimpleTest
135
        function testFetchAll()
136
        {
137
            $this->cal->build();
138
            $children = [];
139
            $i = 1;
140
            while ( $Child = $this->cal->fetch() ) {
141
                $children[$i]=$Child;
142
                ++$i;
143
            }
144
            $this->assertEqual($children,$this->cal->fetchAll());
145
        }
146
    */
147
    public function testSelection()
148
    {
149
        require_once CALENDAR_ROOT . 'Week.php';
150
        $selection = [new Calendar_Week(2003, 10, 12)];
151
        $this->cal->build($selection);
152
        $i        = 1;
153
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 3 : 2;
154
        while ($Child = $this->cal->fetch()) {
155
            if ($i == $expected) {
156
                //12-10-2003 is in the 2nd week of the month if firstDay is Monday,
157
                //in the 3rd if firstDay is Sunday
158
                break;
159
            }
160
            ++$i;
161
        }
162
        $this->assertTrue($Child->isSelected());
163
    }
164
165
    public function testEmptyDaysBefore_AfterAdjust()
166
    {
167
        $this->cal = new Calendar_Month_Weeks(2004, 0);
168
        $this->cal->build();
169
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0;
170
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore());
171
    }
172
}
173
174
if (!defined('TEST_RUNNING')) {
175
    define('TEST_RUNNING', true);
176
    $test = new TestOfMonthWeeks();
177
    $test->run(new HtmlReporter());
0 ignored issues
show
Bug introduced by
The type HtmlReporter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
178
    $test = new TestOfMonthWeeksBuild();
179
    $test->run(new HtmlReporter());
180
}
181