TestOfMonthWeekdays   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 16
eloc 25
dl 0
loc 91
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A testNextHour() 0 3 1
A testPrevHour() 0 3 1
A testPrevSecond() 0 3 1
A testNextSecond() 0 3 1
A testThisMinute() 0 3 1
A __construct() 0 3 1
A testThisDay() 0 3 1
A testThisSecond() 0 3 1
A testNextDay() 0 3 1
A testPrevDay() 0 3 1
A testThisHour() 0 3 1
A setUp() 0 3 1
A testPrevDay_Array() 0 10 1
A testPrevMinute() 0 3 1
A testNextMinute() 0 3 1
A testGetTimeStamp() 0 4 1
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 TestOfMonthWeekdays.
10
 */
11
class TestOfMonthWeekdays extends TestOfCalendar
12
{
13
    /**
14
     * TestOfMonthWeekdays constructor.
15
     */
16
    public function __construct()
17
    {
18
        $this->UnitTestCase('Test of Month Weekdays');
19
    }
20
21
    public function setUp()
22
    {
23
        $this->cal = new Calendar_Month_Weekdays(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 TestOfMonthWeekdaysBuild.
107
 */
108
class TestOfMonthWeekdaysBuild extends TestOfMonthWeekdays
109
{
110
    /**
111
     * TestOfMonthWeekdaysBuild constructor.
112
     */
113
    public function __construct()
114
    {
115
        $this->UnitTestCase('Test of Month_Weekdays::build()');
116
    }
117
118
    public function testSize()
119
    {
120
        $this->cal->build();
121
        $this->assertEqual(35, $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(35, $i);
132
    }
133
134
    public function testFetchAll()
135
    {
136
        $this->cal->build();
137
        $children = [];
138
        $i        = 1;
139
        while ($Child = $this->cal->fetch()) {
140
            $children[$i] = $Child;
141
            ++$i;
142
        }
143
        $this->assertEqual($children, $this->cal->fetchAll());
144
    }
145
146
    public function testSelection()
147
    {
148
        require_once CALENDAR_ROOT . 'Day.php';
149
        $selection = [new Calendar_Day(2003, 10, 25)];
150
        $this->cal->build($selection);
151
        $daysInPrevMonth = (0 == CALENDAR_FIRST_DAY_OF_WEEK) ? 3 : 2;
152
        $end             = 25 + $daysInPrevMonth;
153
        $i               = 1;
154
        while ($Child = $this->cal->fetch()) {
155
            if ($i == $end) {
156
                break;
157
            }
158
            ++$i;
159
        }
160
        $this->assertTrue($Child->isSelected());
161
        $this->assertEqual(25, $Child->day);
162
    }
163
164
    public function testEmptyCount()
165
    {
166
        $this->cal->build();
167
        $empty = 0;
168
        while ($Child = $this->cal->fetch()) {
169
            if ($Child->isEmpty()) {
170
                ++$empty;
171
            }
172
        }
173
        $this->assertEqual(4, $empty);
174
    }
175
176
    public function testEmptyCount2()
177
    {
178
        $this->cal = new Calendar_Month_Weekdays(2010, 3);
179
        $this->cal->build();
180
        $empty = 0;
181
        while ($Child = $this->cal->fetch()) {
182
            if ($Child->isEmpty()) {
183
                ++$empty;
184
            }
185
        }
186
        $this->assertEqual(4, $empty);
187
    }
188
189
    public function testEmptyCount3()
190
    {
191
        $this->cal = new Calendar_Month_Weekdays(2010, 6);
192
        $this->cal->build();
193
        $empty = 0;
194
        while ($Child = $this->cal->fetch()) {
195
            if ($Child->isEmpty()) {
196
                ++$empty;
197
            }
198
        }
199
        $this->assertEqual(5, $empty);
200
    }
201
202
    public function testEmptyDaysBefore_AfterAdjust()
203
    {
204
        $this->cal = new Calendar_Month_Weekdays(2004, 0);
205
        $this->cal->build();
206
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0;
207
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore());
208
    }
209
210
    public function testEmptyDaysBefore()
211
    {
212
        $this->cal = new Calendar_Month_Weekdays(2010, 3);
213
        $this->cal->build();
214
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 1 : 0;
215
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore());
216
    }
217
218
    public function testEmptyDaysBefore2()
219
    {
220
        $this->cal = new Calendar_Month_Weekdays(2010, 6);
221
        $this->cal->build();
222
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 2 : 1;
223
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysBefore());
224
    }
225
226
    public function testEmptyDaysAfter()
227
    {
228
        $this->cal = new Calendar_Month_Weekdays(2010, 3);
229
        $this->cal->build();
230
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 30 : 31;
231
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysAfter());
232
    }
233
234
    public function testEmptyDaysAfter2()
235
    {
236
        $this->cal = new Calendar_Month_Weekdays(2010, 6);
237
        $this->cal->build();
238
        $expected = (CALENDAR_FIRST_DAY_OF_WEEK == 0) ? 30 : 31;
239
        $this->assertEqual($expected, $this->cal->tableHelper->getEmptyDaysAfter());
240
    }
241
}
242
243
if (!defined('TEST_RUNNING')) {
244
    define('TEST_RUNNING', true);
245
    $test = new TestOfMonthWeekdays();
246
    $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...
247
    $test = new TestOfMonthWeekdaysBuild();
248
    $test->run(new HtmlReporter());
249
}
250