TestOfWeek   A
last analyzed

Complexity

Total Complexity 31

Size/Duplication

Total Lines 256
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 31
eloc 118
dl 0
loc 256
rs 9.92
c 0
b 0
f 0

31 Methods

Rating   Name   Duplication   Size   Complexity  
A testThisHour() 0 3 1
A testPrevDay() 0 3 1
A setUp() 0 3 1
A testNextDay() 0 3 1
A testGetTimeStamp() 0 4 1
A testNextWeekInYear() 0 3 1
A testNextSecond() 0 3 1
A testNextHour() 0 3 1
A testPrevHour() 0 3 1
A testPrevSecond() 0 3 1
A testPrevMinute() 0 3 1
A testThisSecond() 0 3 1
A testThisMinute() 0 3 1
A __construct() 0 3 1
A testThisDay() 0 3 1
A testNextMinute() 0 3 1
A testThisWeekInMonth() 0 12 1
A testPrevWeekArray() 0 11 1
A testPrevWeekInMonth() 0 6 1
A testPrevWeekObject() 0 5 1
A testThisYear() 0 35 1
A testNextWeekArray() 0 11 1
A testThisWeekObject() 0 5 1
A testNewTimeStamp() 0 7 1
A testPrevDay_Array() 0 10 1
A testThisWeekArray() 0 11 1
A testPrevWeekInYear() 0 6 1
A testThisWeekInYear() 0 6 1
A testNextWeekInMonth() 0 6 1
A testNextWeekObject() 0 5 1
A testFirstWeekInYear() 0 5 1
1
<?php
2
3
define('CALENDAR_FIRST_DAY_OF_WEEK', 1); //force firstDay = monday
4
5
require_once __DIR__ . '/simple_include.php';
6
require_once __DIR__ . '/calendar_include.php';
7
8
require_once __DIR__ . '/./calendar_test.php';
9
10
/**
11
 * Class TestOfWeek.
12
 */
13
class TestOfWeek extends TestOfCalendar
14
{
15
    /**
16
     * TestOfWeek constructor.
17
     */
18
    public function __construct()
19
    {
20
        $this->UnitTestCase('Test of Week');
21
    }
22
23
    public function setUp()
24
    {
25
        $this->cal = Calendar_Factory::create('Week', 2003, 10, 9);
26
        //print_r($this->cal);
27
    }
28
29
    public function testThisYear()
30
    {
31
        $this->assertEqual(2003, $this->cal->thisYear());
32
33
        $stamp = mktime(0, 0, 0, 1, 1, 2003);
34
        $this->cal->setTimestamp($stamp);
35
        $this->assertEqual(2003, $this->cal->thisYear());
36
37
        $stamp = mktime(0, 0, 0, 12, 31, 2003);
38
        $this->cal->setTimestamp($stamp);
39
        $this->assertEqual(2004, $this->cal->thisYear());
40
41
        $stamp = mktime(0, 0, 0, 1, 1, 2005);
42
        $this->cal->setTimestamp($stamp);
43
        $this->assertEqual(2004, $this->cal->thisYear());
44
45
        $stamp = mktime(0, 0, 0, 12, 31, 2004);
46
        $this->cal->setTimestamp($stamp);
47
        $this->assertEqual(2004, $this->cal->thisYear());
48
49
        $stamp = mktime(0, 0, 0, 1, 1, 2005);
50
        $this->cal->setTimestamp($stamp);
51
        $this->assertEqual(2004, $this->cal->thisYear());
52
53
        $stamp = mktime(0, 0, 0, 12, 31, 2005);
54
        $this->cal->setTimestamp($stamp);
55
        $this->assertEqual(2005, $this->cal->thisYear());
56
57
        $stamp = mktime(0, 0, 0, 1, 1, 2006);
58
        $this->cal->setTimestamp($stamp);
59
        $this->assertEqual(2005, $this->cal->thisYear());
60
61
        $stamp = mktime(0, 0, 0, 12, 31, 2006);
62
        $this->cal->setTimestamp($stamp);
63
        $this->assertEqual(2006, $this->cal->thisYear());
64
    }
65
66
    public function testPrevDay()
67
    {
68
        $this->assertEqual(8, $this->cal->prevDay());
69
    }
70
71
    public function testPrevDay_Array()
72
    {
73
        $this->assertEqual([
74
                               'year'   => 2003,
75
                               'month'  => 10,
76
                               'day'    => 8,
77
                               'hour'   => 0,
78
                               'minute' => 0,
79
                               'second' => 0,
80
                           ], $this->cal->prevDay('array'));
81
    }
82
83
    public function testThisDay()
84
    {
85
        $this->assertEqual(9, $this->cal->thisDay());
86
    }
87
88
    public function testNextDay()
89
    {
90
        $this->assertEqual(10, $this->cal->nextDay());
91
    }
92
93
    public function testPrevHour()
94
    {
95
        $this->assertEqual(23, $this->cal->prevHour());
96
    }
97
98
    public function testThisHour()
99
    {
100
        $this->assertEqual(0, $this->cal->thisHour());
101
    }
102
103
    public function testNextHour()
104
    {
105
        $this->assertEqual(1, $this->cal->nextHour());
106
    }
107
108
    public function testPrevMinute()
109
    {
110
        $this->assertEqual(59, $this->cal->prevMinute());
111
    }
112
113
    public function testThisMinute()
114
    {
115
        $this->assertEqual(0, $this->cal->thisMinute());
116
    }
117
118
    public function testNextMinute()
119
    {
120
        $this->assertEqual(1, $this->cal->nextMinute());
121
    }
122
123
    public function testPrevSecond()
124
    {
125
        $this->assertEqual(59, $this->cal->prevSecond());
126
    }
127
128
    public function testThisSecond()
129
    {
130
        $this->assertEqual(0, $this->cal->thisSecond());
131
    }
132
133
    public function testNextSecond()
134
    {
135
        $this->assertEqual(1, $this->cal->nextSecond());
136
    }
137
138
    public function testGetTimeStamp()
139
    {
140
        $stamp = mktime(0, 0, 0, 10, 9, 2003);
141
        $this->assertEqual($stamp, $this->cal->getTimestamp());
142
    }
143
144
    public function testNewTimeStamp()
145
    {
146
        $stamp = mktime(0, 0, 0, 7, 28, 2004);
147
        $this->cal->setTimestamp($stamp);
148
        $this->assertEqual('30 2004', date('W Y', $this->cal->prevWeek(true)));
149
        $this->assertEqual('31 2004', date('W Y', $this->cal->thisWeek(true)));
150
        $this->assertEqual('32 2004', date('W Y', $this->cal->nextWeek(true)));
151
    }
152
153
    public function testPrevWeekInMonth()
154
    {
155
        $this->assertEqual(1, $this->cal->prevWeek());
156
        $stamp = mktime(0, 0, 0, 2, 3, 2005);
157
        $this->cal->setTimestamp($stamp);
158
        $this->assertEqual(0, $this->cal->prevWeek());
159
    }
160
161
    public function testThisWeekInMonth()
162
    {
163
        $this->assertEqual(2, $this->cal->thisWeek());
164
        $stamp = mktime(0, 0, 0, 2, 3, 2005);
165
        $this->cal->setTimestamp($stamp);
166
        $this->assertEqual(1, $this->cal->thisWeek());
167
        $stamp = mktime(0, 0, 0, 1, 1, 2005);
168
        $this->cal->setTimestamp($stamp);
169
        $this->assertEqual(1, $this->cal->thisWeek());
170
        $stamp = mktime(0, 0, 0, 1, 3, 2005);
171
        $this->cal->setTimestamp($stamp);
172
        $this->assertEqual(2, $this->cal->thisWeek());
173
    }
174
175
    public function testNextWeekInMonth()
176
    {
177
        $this->assertEqual(3, $this->cal->nextWeek());
178
        $stamp = mktime(0, 0, 0, 2, 3, 2005);
179
        $this->cal->setTimestamp($stamp);
180
        $this->assertEqual(2, $this->cal->nextWeek());
181
    }
182
183
    public function testPrevWeekInYear()
184
    {
185
        $this->assertEqual(date('W', $this->cal->prevWeek('timestamp')), $this->cal->prevWeek('n_in_year'));
186
        $stamp = mktime(0, 0, 0, 1, 1, 2004);
187
        $this->cal->setTimestamp($stamp);
188
        $this->assertEqual(date('W', $this->cal->nextWeek('timestamp')), $this->cal->nextWeek('n_in_year'));
189
    }
190
191
    public function testThisWeekInYear()
192
    {
193
        $this->assertEqual(date('W', $this->cal->thisWeek('timestamp')), $this->cal->thisWeek('n_in_year'));
194
        $stamp = mktime(0, 0, 0, 1, 1, 2004);
195
        $this->cal->setTimestamp($stamp);
196
        $this->assertEqual(date('W', $this->cal->thisWeek('timestamp')), $this->cal->thisWeek('n_in_year'));
197
    }
198
199
    public function testFirstWeekInYear()
200
    {
201
        $stamp = mktime(0, 0, 0, 1, 4, 2004);
202
        $this->cal->setTimestamp($stamp);
203
        $this->assertEqual(1, $this->cal->thisWeek('n_in_year'));
204
    }
205
206
    public function testNextWeekInYear()
207
    {
208
        $this->assertEqual(date('W', $this->cal->nextWeek('timestamp')), $this->cal->nextWeek('n_in_year'));
209
    }
210
211
    public function testPrevWeekArray()
212
    {
213
        $testArray = [
214
            'year'   => 2003,
215
            'month'  => 9,
216
            'day'    => 29,
217
            'hour'   => 0,
218
            'minute' => 0,
219
            'second' => 0,
220
        ];
221
        $this->assertEqual($testArray, $this->cal->prevWeek('array'));
222
    }
223
224
    public function testThisWeekArray()
225
    {
226
        $testArray = [
227
            'year'   => 2003,
228
            'month'  => 10,
229
            'day'    => 6,
230
            'hour'   => 0,
231
            'minute' => 0,
232
            'second' => 0,
233
        ];
234
        $this->assertEqual($testArray, $this->cal->thisWeek('array'));
235
    }
236
237
    public function testNextWeekArray()
238
    {
239
        $testArray = [
240
            'year'   => 2003,
241
            'month'  => 10,
242
            'day'    => 13,
243
            'hour'   => 0,
244
            'minute' => 0,
245
            'second' => 0,
246
        ];
247
        $this->assertEqual($testArray, $this->cal->nextWeek('array'));
248
    }
249
250
    public function testPrevWeekObject()
251
    {
252
        $testWeek = Calendar_Factory::create('Week', 2003, 9, 29); //week starts on monday
253
        $Week     = $this->cal->prevWeek('object');
254
        $this->assertEqual($testWeek->getTimestamp(), $Week->getTimestamp());
255
    }
256
257
    public function testThisWeekObject()
258
    {
259
        $testWeek = Calendar_Factory::create('Week', 2003, 10, 6); //week starts on monday
260
        $Week     = $this->cal->thisWeek('object');
261
        $this->assertEqual($testWeek->getTimestamp(), $Week->getTimestamp());
262
    }
263
264
    public function testNextWeekObject()
265
    {
266
        $testWeek = Calendar_Factory::create('Week', 2003, 10, 13); //week starts on monday
267
        $Week     = $this->cal->nextWeek('object');
268
        $this->assertEqual($testWeek->getTimestamp(), $Week->getTimestamp());
269
    }
270
}
271
272
/**
273
 * Class TestOfWeekBuild.
274
 */
275
class TestOfWeekBuild extends TestOfWeek
276
{
277
    /**
278
     * TestOfWeekBuild constructor.
279
     */
280
    public function __construct()
281
    {
282
        $this->UnitTestCase('Test of Week::build()');
283
    }
284
285
    public function testSize()
286
    {
287
        $this->cal->build();
288
        $this->assertEqual(7, $this->cal->size());
289
    }
290
291
    public function testFetch()
292
    {
293
        $this->cal->build();
294
        $i = 0;
295
        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...
296
            ++$i;
297
        }
298
        $this->assertEqual(7, $i);
299
    }
300
301
    public function testFetchAll()
302
    {
303
        $this->cal->build();
304
        $children = [];
305
        $i        = 1;
306
        while ($Child = $this->cal->fetch()) {
307
            $children[$i] = $Child;
308
            ++$i;
309
        }
310
        $this->assertEqual($children, $this->cal->fetchAll());
311
    }
312
313
    public function testSelection()
314
    {
315
        require_once CALENDAR_ROOT . 'Day.php';
316
        $selection = [Calendar_Factory::create('Day', 2003, 10, 7)];
317
        $this->cal->build($selection);
318
        $i = 1;
319
        while ($Child = $this->cal->fetch()) {
320
            if (2 == $i) {
321
                break; //07-10-2003 is the 2nd day of the week (starting on monday)
322
            }
323
            ++$i;
324
        }
325
        $this->assertTrue($Child->isSelected());
326
    }
327
328
    public function testSelectionCornerCase()
329
    {
330
        require_once CALENDAR_ROOT . 'Day.php';
331
        $selectedDays = [
332
            Calendar_Factory::create('Day', 2003, 12, 29),
333
            Calendar_Factory::create('Day', 2003, 12, 30),
334
            Calendar_Factory::create('Day', 2003, 12, 31),
335
            Calendar_Factory::create('Day', 2004, 01, 01),
336
            Calendar_Factory::create('Day', 2004, 01, 02),
337
            Calendar_Factory::create('Day', 2004, 01, 03),
338
            Calendar_Factory::create('Day', 2004, 01, 04),
339
        ];
340
        $this->cal    = Calendar_Factory::create('Week', 2003, 12, 31, 0);
341
        $this->cal->build($selectedDays);
342
        while ($Day = $this->cal->fetch()) {
343
            $this->assertTrue($Day->isSelected());
344
        }
345
        $this->cal = Calendar_Factory::create('Week', 2004, 1, 1, 0);
346
        $this->cal->build($selectedDays);
347
        while ($Day = $this->cal->fetch()) {
348
            $this->assertTrue($Day->isSelected());
349
        }
350
    }
351
}
352
353
if (!defined('TEST_RUNNING')) {
354
    define('TEST_RUNNING', true);
355
    $test = new TestOfWeek();
356
    $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...
357
    $test = new TestOfWeekBuild();
358
    $test->run(new HtmlReporter());
359
}
360