@@ -184,4 +184,109 @@ public function provideIntervals()
184
184
array ('P1Y2M3DT4H5M6S ' , 1 , '- 1y 2m 3d 04:05:06 ' .$ ms , null ),
185
185
);
186
186
}
187
+
188
+ /**
189
+ * @dataProvider provideTimeZones
190
+ */
191
+ public function testDumpTimeZone ($ timezone , $ expected )
192
+ {
193
+ if ((defined ('HHVM_VERSION_ID ' ) || PHP_VERSION_ID <= 50509 ) && !preg_match ('/\w+\/\w+/ ' , $ timezone )) {
194
+ $ this ->markTestSkipped ('DateTimeZone GMT offsets are supported since 5.5.10. See https://github.com/facebook/hhvm/issues/5875 for HHVM. ' );
195
+ }
196
+
197
+ $ timezone = new \DateTimeZone ($ timezone );
198
+
199
+ $ xDump = <<<EODUMP
200
+ DateTimeZone {
201
+ timezone: $ expected
202
+ %A}
203
+ EODUMP ;
204
+
205
+ $ this ->assertDumpMatchesFormat ($ xDump , $ timezone );
206
+ }
207
+
208
+ /**
209
+ * @dataProvider provideTimeZones
210
+ */
211
+ public function testDumpTimeZoneExcludingVerbosity ($ timezone , $ expected )
212
+ {
213
+ if ((defined ('HHVM_VERSION_ID ' ) || PHP_VERSION_ID <= 50509 ) && !preg_match ('/\w+\/\w+/ ' , $ timezone )) {
214
+ $ this ->markTestSkipped ('DateTimeZone GMT offsets are supported since 5.5.10. See https://github.com/facebook/hhvm/issues/5875 for HHVM. ' );
215
+ }
216
+
217
+ $ timezone = new \DateTimeZone ($ timezone );
218
+
219
+ $ xDump = <<<EODUMP
220
+ DateTimeZone {
221
+ timezone: $ expected
222
+ }
223
+ EODUMP ;
224
+
225
+ $ this ->assertDumpMatchesFormat ($ xDump , $ timezone , Caster::EXCLUDE_VERBOSE );
226
+ }
227
+
228
+ /**
229
+ * @dataProvider provideTimeZones
230
+ */
231
+ public function testCastTimeZone ($ timezone , $ xTimezone , $ xRegion )
232
+ {
233
+ if ((defined ('HHVM_VERSION_ID ' ) || PHP_VERSION_ID <= 50509 ) && !preg_match ('/\w+\/\w+/ ' , $ timezone )) {
234
+ $ this ->markTestSkipped ('DateTimeZone GMT offsets are supported since 5.5.10. See https://github.com/facebook/hhvm/issues/5875 for HHVM. ' );
235
+ }
236
+
237
+ $ timezone = new \DateTimeZone ($ timezone );
238
+ $ stub = new Stub ();
239
+
240
+ $ cast = DateCaster::castTimeZone ($ timezone , array ('foo ' => 'bar ' ), $ stub , false , Caster::EXCLUDE_VERBOSE );
241
+
242
+ $ xDump = <<<EODUMP
243
+ array:1 [
244
+ "\\x00~\\x00timezone" => $ xTimezone
245
+ ]
246
+ EODUMP ;
247
+
248
+ $ this ->assertDumpMatchesFormat ($ xDump , $ cast );
249
+
250
+ $ xDump = <<<EODUMP
251
+ Symfony\Component\VarDumper\Caster\ConstStub {
252
+ +type: "ref"
253
+ +class: " $ xTimezone"
254
+ +value: " $ xRegion"
255
+ +cut: 0
256
+ +handle: 0
257
+ +refCount: 0
258
+ +position: 0
259
+ +attr: []
260
+ }
261
+ EODUMP ;
262
+
263
+ $ this ->assertDumpMatchesFormat ($ xDump , $ cast ["\0~ \0timezone " ]);
264
+ }
265
+
266
+ public function provideTimeZones ()
267
+ {
268
+ $ xRegion = extension_loaded ('intl ' ) ? '%s ' : '' ;
269
+
270
+ return array (
271
+ // type 1 (UTC offset)
272
+ array ('-12:00 ' , '-12:00 ' , '' ),
273
+ array ('+00:00 ' , '+00:00 ' , '' ),
274
+ array ('+14:00 ' , '+14:00 ' , '' ),
275
+
276
+ // type 2 (timezone abbreviation)
277
+ array ('GMT ' , '+00:00 ' , '' ),
278
+ array ('a ' , '+01:00 ' , '' ),
279
+ array ('b ' , '+02:00 ' , '' ),
280
+ array ('z ' , '+00:00 ' , '' ),
281
+
282
+ // type 3 (timezone identifier)
283
+ array ('Africa/Tunis ' , 'Africa/Tunis (+01:00) ' , $ xRegion ),
284
+ array ('America/Panama ' , 'America/Panama (-05:00) ' , $ xRegion ),
285
+ array ('Asia/Jerusalem ' , 'Asia/Jerusalem (+03:00) ' , $ xRegion ),
286
+ array ('Atlantic/Canary ' , 'Atlantic/Canary (+01:00) ' , $ xRegion ),
287
+ array ('Australia/Perth ' , 'Australia/Perth (+08:00) ' , $ xRegion ),
288
+ array ('Europe/Zurich ' , 'Europe/Zurich (+02:00) ' , $ xRegion ),
289
+ array ('Pacific/Tahiti ' , 'Pacific/Tahiti (-10:00) ' , $ xRegion ),
290
+ );
291
+ }
187
292
}
0 commit comments