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 TestOfDay. |
11
|
|
|
*/ |
12
|
|
|
class TestOfDay extends TestOfCalendar |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* TestOfDay constructor. |
16
|
|
|
*/ |
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
$this->UnitTestCase('Test of Day'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->cal = new Calendar_Day(2003, 10, 25); |
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 testPrevHour() |
40
|
|
|
{ |
41
|
|
|
$this->assertEqual(23, $this->cal->prevHour()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testThisHour() |
45
|
|
|
{ |
46
|
|
|
$this->assertEqual(0, $this->cal->thisHour()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testNextHour() |
50
|
|
|
{ |
51
|
|
|
$this->assertEqual(1, $this->cal->nextHour()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testPrevMinute() |
55
|
|
|
{ |
56
|
|
|
$this->assertEqual(59, $this->cal->prevMinute()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testThisMinute() |
60
|
|
|
{ |
61
|
|
|
$this->assertEqual(0, $this->cal->thisMinute()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testNextMinute() |
65
|
|
|
{ |
66
|
|
|
$this->assertEqual(1, $this->cal->nextMinute()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testPrevSecond() |
70
|
|
|
{ |
71
|
|
|
$this->assertEqual(59, $this->cal->prevSecond()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testThisSecond() |
75
|
|
|
{ |
76
|
|
|
$this->assertEqual(0, $this->cal->thisSecond()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testNextSecond() |
80
|
|
|
{ |
81
|
|
|
$this->assertEqual(1, $this->cal->nextSecond()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testGetTimeStamp() |
85
|
|
|
{ |
86
|
|
|
$stamp = mktime(0, 0, 0, 10, 25, 2003); |
87
|
|
|
$this->assertEqual($stamp, $this->cal->getTimestamp()); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Class TestOfDayBuild. |
93
|
|
|
*/ |
94
|
|
|
class TestOfDayBuild extends TestOfDay |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
/** |
97
|
|
|
* TestOfDayBuild constructor. |
98
|
|
|
*/ |
99
|
|
|
public function __construct() |
100
|
|
|
{ |
101
|
|
|
$this->UnitTestCase('Test of Day::build()'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testSize() |
105
|
|
|
{ |
106
|
|
|
$this->cal->build(); |
107
|
|
|
$this->assertEqual(24, $this->cal->size()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testFetch() |
111
|
|
|
{ |
112
|
|
|
$this->cal->build(); |
113
|
|
|
$i = 0; |
114
|
|
|
while ($Child = $this->cal->fetch()) { |
|
|
|
|
115
|
|
|
++$i; |
116
|
|
|
} |
117
|
|
|
$this->assertEqual(24, $i); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testFetchAll() |
121
|
|
|
{ |
122
|
|
|
$this->cal->build(); |
123
|
|
|
$children = []; |
124
|
|
|
$i = 0; |
125
|
|
|
while ($Child = $this->cal->fetch()) { |
126
|
|
|
$children[$i] = $Child; |
127
|
|
|
++$i; |
128
|
|
|
} |
129
|
|
|
$this->assertEqual($children, $this->cal->fetchAll()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testSelection() |
133
|
|
|
{ |
134
|
|
|
require_once CALENDAR_ROOT . 'Hour.php'; |
135
|
|
|
$selection = [new Calendar_Hour(2003, 10, 25, 13)]; |
136
|
|
|
$this->cal->build($selection); |
137
|
|
|
$i = 0; |
138
|
|
|
while ($Child = $this->cal->fetch()) { |
139
|
|
|
if (13 == $i) { |
140
|
|
|
break; |
141
|
|
|
} |
142
|
|
|
++$i; |
143
|
|
|
} |
144
|
|
|
$this->assertTrue($Child->isSelected()); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
if (!defined('TEST_RUNNING')) { |
149
|
|
|
define('TEST_RUNNING', true); |
150
|
|
|
$test = new TestOfDay(); |
151
|
|
|
$test->run(new HtmlReporter()); |
|
|
|
|
152
|
|
|
$test = new TestOfDayBuild(); |
153
|
|
|
$test->run(new HtmlReporter()); |
154
|
|
|
} |
155
|
|
|
|
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.