1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// |
3
|
|
|
|
4
|
|
|
require_once __DIR__ . '/simple_include.php'; |
5
|
|
|
require_once __DIR__ . '/calendar_include.php'; |
6
|
|
|
|
7
|
|
|
require_once __DIR__ . '/./calendar_test.php'; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class TestOfHour. |
11
|
|
|
*/ |
12
|
|
|
class TestOfHour extends TestOfCalendar |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* TestOfHour constructor. |
16
|
|
|
*/ |
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
$this->UnitTestCase('Test of Hour'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->cal = new Calendar_Hour(2003, 10, 25, 13); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testPrevDay_Array() |
28
|
|
|
{ |
29
|
|
|
$this->assertEqual([ |
30
|
|
|
'year' => 2003, |
31
|
|
|
'month' => 10, |
32
|
|
|
'day' => 24, |
33
|
|
|
'hour' => 0, |
34
|
|
|
'minute' => 0, |
35
|
|
|
'second' => 0, |
36
|
|
|
], $this->cal->prevDay('array')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testPrevMinute() |
40
|
|
|
{ |
41
|
|
|
$this->assertEqual(59, $this->cal->prevMinute()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testThisMinute() |
45
|
|
|
{ |
46
|
|
|
$this->assertEqual(0, $this->cal->thisMinute()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testNextMinute() |
50
|
|
|
{ |
51
|
|
|
$this->assertEqual(1, $this->cal->nextMinute()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testPrevSecond() |
55
|
|
|
{ |
56
|
|
|
$this->assertEqual(59, $this->cal->prevSecond()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testThisSecond() |
60
|
|
|
{ |
61
|
|
|
$this->assertEqual(0, $this->cal->thisSecond()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testNextSecond() |
65
|
|
|
{ |
66
|
|
|
$this->assertEqual(1, $this->cal->nextSecond()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetTimeStamp() |
70
|
|
|
{ |
71
|
|
|
$stamp = mktime(13, 0, 0, 10, 25, 2003); |
72
|
|
|
$this->assertEqual($stamp, $this->cal->getTimestamp()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Class TestOfHourBuild. |
78
|
|
|
*/ |
79
|
|
|
class TestOfHourBuild extends TestOfHour |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
/** |
82
|
|
|
* TestOfHourBuild constructor. |
83
|
|
|
*/ |
84
|
|
|
public function __construct() |
85
|
|
|
{ |
86
|
|
|
$this->UnitTestCase('Test of Hour::build()'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testSize() |
90
|
|
|
{ |
91
|
|
|
$this->cal->build(); |
92
|
|
|
$this->assertEqual(_EXTCAL_TS_MINUTE, $this->cal->size()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testFetch() |
96
|
|
|
{ |
97
|
|
|
$this->cal->build(); |
98
|
|
|
$i = 0; |
99
|
|
|
while ($Child = $this->cal->fetch()) { |
|
|
|
|
100
|
|
|
++$i; |
101
|
|
|
} |
102
|
|
|
$this->assertEqual(_EXTCAL_TS_MINUTE, $i); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testFetchAll() |
106
|
|
|
{ |
107
|
|
|
$this->cal->build(); |
108
|
|
|
$children = []; |
109
|
|
|
$i = 0; |
110
|
|
|
while ($Child = $this->cal->fetch()) { |
111
|
|
|
$children[$i] = $Child; |
112
|
|
|
++$i; |
113
|
|
|
} |
114
|
|
|
$this->assertEqual($children, $this->cal->fetchAll()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testSelection() |
118
|
|
|
{ |
119
|
|
|
require_once CALENDAR_ROOT . 'Minute.php'; |
120
|
|
|
$selection = [new Calendar_Minute(2003, 10, 25, 13, 32)]; |
121
|
|
|
$this->cal->build($selection); |
122
|
|
|
$i = 0; |
123
|
|
|
while ($Child = $this->cal->fetch()) { |
124
|
|
|
if (32 == $i) { |
125
|
|
|
break; |
126
|
|
|
} |
127
|
|
|
++$i; |
128
|
|
|
} |
129
|
|
|
$this->assertTrue($Child->isSelected()); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
if (!defined('TEST_RUNNING')) { |
134
|
|
|
define('TEST_RUNNING', true); |
135
|
|
|
$test = new TestOfHour(); |
136
|
|
|
$test->run(new HtmlReporter()); |
|
|
|
|
137
|
|
|
$test = new TestOfHourBuild(); |
138
|
|
|
$test->run(new HtmlReporter()); |
139
|
|
|
} |
140
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.