|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
// |
|
3
|
|
|
|
|
4
|
|
|
require_once __DIR__ . '/simple_include.php'; |
|
5
|
|
|
require_once __DIR__ . '/calendar_include.php'; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class TestOfCalendar. |
|
9
|
|
|
*/ |
|
10
|
|
|
class TestOfCalendar extends UnitTestCase |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
public $cal; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param string $name |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct($name = 'Test of Calendar') |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct($name); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->cal = new Calendar(2003, 10, 25, 13, 32, 43); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function tearDown() |
|
28
|
|
|
{ |
|
29
|
|
|
unset($this->cal); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testPrevYear() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertEqual(2002, $this->cal->prevYear()); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testPrevYear_Array() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->assertEqual([ |
|
40
|
|
|
'year' => 2002, |
|
41
|
|
|
'month' => 1, |
|
42
|
|
|
'day' => 1, |
|
43
|
|
|
'hour' => 0, |
|
44
|
|
|
'minute' => 0, |
|
45
|
|
|
'second' => 0, |
|
46
|
|
|
], $this->cal->prevYear('array')); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testThisYear() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->assertEqual(2003, $this->cal->thisYear()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testNextYear() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertEqual(2004, $this->cal->nextYear()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testPrevMonth() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->assertEqual(9, $this->cal->prevMonth()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testPrevMonth_Array() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->assertEqual([ |
|
67
|
|
|
'year' => 2003, |
|
68
|
|
|
'month' => 9, |
|
69
|
|
|
'day' => 1, |
|
70
|
|
|
'hour' => 0, |
|
71
|
|
|
'minute' => 0, |
|
72
|
|
|
'second' => 0, |
|
73
|
|
|
], $this->cal->prevMonth('array')); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testThisMonth() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->assertEqual(10, $this->cal->thisMonth()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testNextMonth() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->assertEqual(11, $this->cal->nextMonth()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testPrevDay() |
|
87
|
|
|
{ |
|
88
|
|
|
$this->assertEqual(24, $this->cal->prevDay()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testPrevDay_Array() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->assertEqual([ |
|
94
|
|
|
'year' => 2003, |
|
95
|
|
|
'month' => 10, |
|
96
|
|
|
'day' => 24, |
|
97
|
|
|
'hour' => 0, |
|
98
|
|
|
'minute' => 0, |
|
99
|
|
|
'second' => 0, |
|
100
|
|
|
], $this->cal->prevDay('array')); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function testThisDay() |
|
104
|
|
|
{ |
|
105
|
|
|
$this->assertEqual(25, $this->cal->thisDay()); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function testNextDay() |
|
109
|
|
|
{ |
|
110
|
|
|
$this->assertEqual(26, $this->cal->nextDay()); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function testPrevHour() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->assertEqual(12, $this->cal->prevHour()); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function testThisHour() |
|
119
|
|
|
{ |
|
120
|
|
|
$this->assertEqual(13, $this->cal->thisHour()); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function testNextHour() |
|
124
|
|
|
{ |
|
125
|
|
|
$this->assertEqual(14, $this->cal->nextHour()); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function testPrevMinute() |
|
129
|
|
|
{ |
|
130
|
|
|
$this->assertEqual(31, $this->cal->prevMinute()); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function testThisMinute() |
|
134
|
|
|
{ |
|
135
|
|
|
$this->assertEqual(32, $this->cal->thisMinute()); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function testNextMinute() |
|
139
|
|
|
{ |
|
140
|
|
|
$this->assertEqual(33, $this->cal->nextMinute()); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function testPrevSecond() |
|
144
|
|
|
{ |
|
145
|
|
|
$this->assertEqual(42, $this->cal->prevSecond()); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function testThisSecond() |
|
149
|
|
|
{ |
|
150
|
|
|
$this->assertEqual(43, $this->cal->thisSecond()); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function testNextSecond() |
|
154
|
|
|
{ |
|
155
|
|
|
$this->assertEqual(44, $this->cal->nextSecond()); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function testSetTimeStamp() |
|
159
|
|
|
{ |
|
160
|
|
|
$stamp = mktime(13, 32, 43, 10, 25, 2003); |
|
161
|
|
|
$this->cal->setTimestamp($stamp); |
|
162
|
|
|
$this->assertEqual($stamp, $this->cal->getTimestamp()); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function testGetTimeStamp() |
|
166
|
|
|
{ |
|
167
|
|
|
$stamp = mktime(13, 32, 43, 10, 25, 2003); |
|
168
|
|
|
$this->assertEqual($stamp, $this->cal->getTimestamp()); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function testIsToday() |
|
172
|
|
|
{ |
|
173
|
|
|
$stamp = time(); |
|
174
|
|
|
$this->cal->setTimestamp($stamp); |
|
175
|
|
|
$this->assertTrue($this->cal->isToday()); |
|
176
|
|
|
|
|
177
|
|
|
$stamp += 1000000000; |
|
178
|
|
|
$this->cal->setTimestamp($stamp); |
|
179
|
|
|
$this->assertFalse($this->cal->isToday()); |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|
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.