|
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 TestOfMonth. |
|
11
|
|
|
*/ |
|
12
|
|
|
class TestOfMonth extends TestOfCalendar |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* TestOfMonth constructor. |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->UnitTestCase('Test of Month'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->cal = new Calendar_Month(2003, 10); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testPrevMonth_Object() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->assertEqual(new Calendar_Month(2003, 9), $this->cal->prevMonth('object')); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testPrevDay() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertEqual(30, $this->cal->prevDay()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testPrevDay_Array() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->assertEqual([ |
|
40
|
|
|
'year' => 2003, |
|
41
|
|
|
'month' => 9, |
|
42
|
|
|
'day' => 30, |
|
43
|
|
|
'hour' => 0, |
|
44
|
|
|
'minute' => 0, |
|
45
|
|
|
'second' => 0, |
|
46
|
|
|
], $this->cal->prevDay('array')); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testThisDay() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->assertEqual(1, $this->cal->thisDay()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testNextDay() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertEqual(2, $this->cal->nextDay()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testPrevHour() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->assertEqual(23, $this->cal->prevHour()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testThisHour() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->assertEqual(0, $this->cal->thisHour()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testNextHour() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->assertEqual(1, $this->cal->nextHour()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testPrevMinute() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertEqual(59, $this->cal->prevMinute()); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testThisMinute() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->assertEqual(0, $this->cal->thisMinute()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testNextMinute() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->assertEqual(1, $this->cal->nextMinute()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testPrevSecond() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->assertEqual(59, $this->cal->prevSecond()); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testThisSecond() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->assertEqual(0, $this->cal->thisSecond()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testNextSecond() |
|
100
|
|
|
{ |
|
101
|
|
|
$this->assertEqual(1, $this->cal->nextSecond()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testGetTimeStamp() |
|
105
|
|
|
{ |
|
106
|
|
|
$stamp = mktime(0, 0, 0, 10, 1, 2003); |
|
107
|
|
|
$this->assertEqual($stamp, $this->cal->getTimestamp()); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Class TestOfMonthBuild. |
|
113
|
|
|
*/ |
|
114
|
|
|
class TestOfMonthBuild extends TestOfMonth |
|
|
|
|
|
|
115
|
|
|
{ |
|
116
|
|
|
/** |
|
117
|
|
|
* TestOfMonthBuild constructor. |
|
118
|
|
|
*/ |
|
119
|
|
|
public function __construct() |
|
120
|
|
|
{ |
|
121
|
|
|
$this->UnitTestCase('Test of Month::build()'); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function testSize() |
|
125
|
|
|
{ |
|
126
|
|
|
$this->cal->build(); |
|
127
|
|
|
$this->assertEqual(31, $this->cal->size()); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function testFetch() |
|
131
|
|
|
{ |
|
132
|
|
|
$this->cal->build(); |
|
133
|
|
|
$i = 0; |
|
134
|
|
|
while ($Child = $this->cal->fetch()) { |
|
|
|
|
|
|
135
|
|
|
++$i; |
|
136
|
|
|
} |
|
137
|
|
|
$this->assertEqual(31, $i); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function testFetchAll() |
|
141
|
|
|
{ |
|
142
|
|
|
$this->cal->build(); |
|
143
|
|
|
$children = []; |
|
144
|
|
|
$i = 1; |
|
145
|
|
|
while ($Child = $this->cal->fetch()) { |
|
146
|
|
|
$children[$i] = $Child; |
|
147
|
|
|
++$i; |
|
148
|
|
|
} |
|
149
|
|
|
$this->assertEqual($children, $this->cal->fetchAll()); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function testSelection() |
|
153
|
|
|
{ |
|
154
|
|
|
require_once CALENDAR_ROOT . 'Day.php'; |
|
155
|
|
|
$selection = [new Calendar_Day(2003, 10, 25)]; |
|
156
|
|
|
$this->cal->build($selection); |
|
157
|
|
|
$i = 1; |
|
158
|
|
|
while ($Child = $this->cal->fetch()) { |
|
159
|
|
|
if (25 == $i) { |
|
160
|
|
|
break; |
|
161
|
|
|
} |
|
162
|
|
|
++$i; |
|
163
|
|
|
} |
|
164
|
|
|
$this->assertTrue($Child->isSelected()); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
if (!defined('TEST_RUNNING')) { |
|
169
|
|
|
define('TEST_RUNNING', true); |
|
170
|
|
|
$test = new TestOfMonth(); |
|
171
|
|
|
$test->run(new HtmlReporter()); |
|
|
|
|
|
|
172
|
|
|
$test = new TestOfMonthBuild(); |
|
173
|
|
|
$test->run(new HtmlReporter()); |
|
174
|
|
|
} |
|
175
|
|
|
|
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.