1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Fichier de test pour une class |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace BFW\test\unit; |
7
|
|
|
use \atoum; |
8
|
|
|
|
9
|
|
|
require_once(__DIR__.'/../common.php'); |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Test de la class Date |
13
|
|
|
*/ |
14
|
|
|
class Date extends atoum |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var $class : Instance de la class Date |
18
|
|
|
*/ |
19
|
|
|
protected $class; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var $mock : Instance du mock pour la class Date |
23
|
|
|
*/ |
24
|
|
|
protected $mock; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Instanciation de la class avant chaque méthode de test |
28
|
|
|
*/ |
29
|
|
|
public function beforeTestMethod($testMethod) |
30
|
|
|
{ |
31
|
|
|
//$this->class = new \BFW\Date(); |
32
|
|
|
$this->mock = new MockDate('2014-10-26 15:01:00+01:00'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Test de la méthode getDate() |
37
|
|
|
*/ |
38
|
|
|
public function testGetDate() |
39
|
|
|
{ |
40
|
|
|
$this->string($this->mock->getDate())->isEqualTo('2014-10-26 15:01:00+0100'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Test de la méthode getAnnee() |
45
|
|
|
*/ |
46
|
|
|
public function testGetAnnee() |
47
|
|
|
{ |
48
|
|
|
$this->string($this->mock->getAnnee())->isEqualTo('2014'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Test de la méthode getMois() |
53
|
|
|
*/ |
54
|
|
|
public function testGetMois() |
55
|
|
|
{ |
56
|
|
|
$this->string($this->mock->getMois())->isEqualTo('10'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Test de la méthode getJour() |
61
|
|
|
*/ |
62
|
|
|
public function testGetJour() |
63
|
|
|
{ |
64
|
|
|
$this->string($this->mock->getJour())->isEqualTo('26'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Test de la méthode getHeure() |
69
|
|
|
*/ |
70
|
|
|
public function testGetHeure() |
71
|
|
|
{ |
72
|
|
|
$this->string($this->mock->getHeure())->isEqualTo('15'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Test de la méthode getMinute() |
77
|
|
|
*/ |
78
|
|
|
public function testGetMinute() |
79
|
|
|
{ |
80
|
|
|
$this->string($this->mock->getMinute())->isEqualTo('01'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Test de la méthode getSeconde() |
85
|
|
|
*/ |
86
|
|
|
public function testGetSeconde() |
87
|
|
|
{ |
88
|
|
|
$this->string($this->mock->getSeconde())->isEqualTo('00'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Test de la méthode getZone() |
93
|
|
|
*/ |
94
|
|
|
public function testGetZone() |
95
|
|
|
{ |
96
|
|
|
$this->string($this->mock->getZone())->isEqualTo('+01:00'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Test du constructeur : Date($date="now") |
101
|
|
|
*/ |
102
|
|
|
public function testDate() |
103
|
|
|
{ |
104
|
|
|
$this->mock = new MockDate; |
105
|
|
|
$date = new \DateTime; |
106
|
|
|
$this->string($this->mock->getDate())->isEqualTo($date->format('Y-m-d H:i:sO')); |
107
|
|
|
|
108
|
|
|
$this->mock = new MockDate('2014-10-26 15:01:00+01:00'); |
109
|
|
|
$this->string($this->mock->getDate())->isEqualTo('2014-10-26 15:01:00+0100'); |
110
|
|
|
|
111
|
|
|
$this->mock = new MockDate('2014-10-26 15:01:00+01'); |
112
|
|
|
$this->string($this->mock->getDate())->isEqualTo('2014-10-26 15:01:00+0100'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Test de la méthode modify($cond) |
117
|
|
|
*/ |
118
|
|
|
public function testModify() |
119
|
|
|
{ |
120
|
|
|
$this->mock->modify('+1 day'); |
121
|
|
|
$this->string($this->mock->getDate())->isEqualTo('2014-10-27 15:01:00+0100'); |
122
|
|
|
|
123
|
|
|
$this->mock = new MockDate('2014-10-26 15:01:00+01:00'); |
124
|
|
|
$this->mock->modify('+1 jour'); |
125
|
|
|
$this->string($this->mock->getDate())->isEqualTo('2014-10-27 15:01:00+0100'); |
126
|
|
|
|
127
|
|
|
$mock = $this->mock; |
128
|
|
|
$this->exception(function() use($mock) |
129
|
|
|
{ |
130
|
|
|
$mock->modify('+1 test'); |
131
|
|
|
})->message->contains('Parameter test is unknown.'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Test de la méthode getSql($decoupe=) |
136
|
|
|
*/ |
137
|
|
|
public function testGetSql() |
138
|
|
|
{ |
139
|
|
|
$this->string($this->mock->getSql())->isEqualTo('2014-10-26 15:01:00'); |
140
|
|
|
$this->array($this->mock->getSql(true))->isEqualTo(array('2014-10-26', '15:01:00')); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Test de la méthode setZone($NewZone) |
145
|
|
|
*/ |
146
|
|
|
public function testSetZone() |
147
|
|
|
{ |
148
|
|
|
$this->mock->setZone('Europe/Paris'); |
149
|
|
|
$dateTimeZone = new \DateTimeZone('Europe/Paris'); |
150
|
|
|
$this->object($this->mock->getTimezone())->isCloneOf($dateTimeZone); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Test de la méthode lst_TimeZone() |
155
|
|
|
*/ |
156
|
|
|
public function testLst_TimeZone() |
157
|
|
|
{ |
158
|
|
|
$dateTimeZone = new \DateTimeZone('Europe/Paris'); |
159
|
|
|
$lstTimeZone = $dateTimeZone->listIdentifiers(); |
160
|
|
|
|
161
|
|
|
$this->array($this->mock->lst_TimeZone())->isEqualTo($lstTimeZone); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Test de la méthode lst_TimeZoneContinent() |
166
|
|
|
*/ |
167
|
|
|
public function testLst_TimeZoneContinent() |
168
|
|
|
{ |
169
|
|
|
$this->array($this->mock->lst_TimeZoneContinent())->isEqualTo(array( |
170
|
|
|
'africa', |
171
|
|
|
'america', |
172
|
|
|
'antartica', |
173
|
|
|
'arctic', |
174
|
|
|
'asia', |
175
|
|
|
'atlantic', |
176
|
|
|
'australia', |
177
|
|
|
'europe', |
178
|
|
|
'indian', |
179
|
|
|
'pacific' |
180
|
|
|
)); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Test de la méthode lst_TimeZonePays($continent) |
185
|
|
|
*/ |
186
|
|
|
public function testLst_TimeZonePays() |
187
|
|
|
{ |
188
|
|
|
$lstAntarticaTimeZone = array( |
189
|
|
|
'Antarctica/Casey', |
190
|
|
|
'Antarctica/Davis', |
191
|
|
|
'Antarctica/DumontDUrville', |
192
|
|
|
'Antarctica/Macquarie', |
193
|
|
|
'Antarctica/Mawson', |
194
|
|
|
'Antarctica/McMurdo', |
195
|
|
|
'Antarctica/Palmer', |
196
|
|
|
'Antarctica/Rothera', |
197
|
|
|
'Antarctica/South_Pole', |
198
|
|
|
'Antarctica/Syowa', |
199
|
|
|
'Antarctica/Troll', |
200
|
|
|
'Antarctica/Vostok' |
201
|
|
|
); |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
$dateTimeZone = new \DateTimeZone('Europe/Paris'); |
205
|
|
|
$lstTimeZone = $dateTimeZone->listIdentifiers(); |
206
|
|
|
|
207
|
|
|
$lstTimeZoneTest = array(); |
208
|
|
|
foreach($lstAntarticaTimeZone as $timeZone) |
209
|
|
|
{ |
210
|
|
|
if(in_array($timeZone, $lstTimeZone)) |
211
|
|
|
{ |
212
|
|
|
$lstTimeZoneTest[] = $timeZone; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
$this->array($this->mock->lst_TimeZonePays('Antarctica'))->isEqualTo($lstTimeZoneTest); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Test de la méthode aff_simple($tout=1, $minus=) |
221
|
|
|
*/ |
222
|
|
|
public function testAff_simple() |
223
|
|
|
{ |
224
|
|
|
//echo $this->mock->aff_simple(); |
225
|
|
|
|
226
|
|
|
$this->mock = new MockDate; |
227
|
|
|
$this->string($this->mock->aff_simple())->isEqualTo('Maintenant'); |
228
|
|
|
|
229
|
|
|
$this->mock->modify('-30 second'); |
230
|
|
|
$this->string($this->mock->aff_simple())->isEqualTo('Il y a 30s'); |
231
|
|
|
|
232
|
|
|
$this->mock->modify('-50 minute'); |
233
|
|
|
$this->string($this->mock->aff_simple())->isEqualTo('Il y a 50min'); |
234
|
|
|
|
235
|
|
|
$this->mock->modify('-10 minute'); |
236
|
|
|
$this->string($this->mock->aff_simple())->isEqualTo('Il y a 01h'); |
237
|
|
|
|
238
|
|
|
$this->mock->modify('-10 minute'); |
239
|
|
|
$this->string($this->mock->aff_simple())->isEqualTo('Il y a 01h'); |
240
|
|
|
|
241
|
|
|
$this->mock->modify('-20 hour'); |
242
|
|
|
$this->string($this->mock->aff_simple())->isEqualTo('Hier à '.$this->mock->format('H:i')); |
243
|
|
|
|
244
|
|
|
$this->mock->modify('-14 day'); |
245
|
|
|
$this->string($this->mock->aff_simple())->isEqualTo('Le '.$this->mock->format('d/m').' à '.$this->mock->format('H:i')); |
246
|
|
|
|
247
|
|
|
$this->mock->modify('-1 year'); |
248
|
|
|
$this->string($this->mock->aff_simple())->isEqualTo('Le '.$this->mock->format('d/m/Y').' à '.$this->mock->format('H:i')); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Mock pour la classe Date |
255
|
|
|
*/ |
256
|
|
|
class MockDate extends \BFW\Date |
257
|
|
|
{ |
258
|
|
|
/** |
259
|
|
|
* Accesseur get |
260
|
|
|
*/ |
261
|
|
|
public function __get($name) {return $this->$name;} |
262
|
|
|
|
263
|
|
|
} |
264
|
|
|
|