@@ -296,4 +296,97 @@ public function provideTimeZones()
296
296
array ('Pacific/Tahiti ' , 'Pacific/Tahiti (-10:00) ' , $ xRegion ),
297
297
);
298
298
}
299
+
300
+ /**
301
+ * @dataProvider providePeriods
302
+ */
303
+ public function testDumpPeriod ($ start , $ interval , $ end , $ options , $ expected )
304
+ {
305
+ if (defined ('HHVM_VERSION_ID ' ) || \PHP_VERSION_ID < 50605 ) {
306
+ $ this ->markTestSkipped ();
307
+ }
308
+
309
+ $ p = new \DatePeriod (new \DateTime ($ start ), new \DateInterval ($ interval ), is_int ($ end ) ? $ end : new \DateTime ($ end ), $ options );
310
+
311
+ $ xDump = <<<EODUMP
312
+ DatePeriod {
313
+ period: $ expected
314
+ %A}
315
+ EODUMP ;
316
+
317
+ $ this ->assertDumpMatchesFormat ($ xDump , $ p );
318
+ }
319
+
320
+ /**
321
+ * @dataProvider providePeriods
322
+ */
323
+ public function testCastPeriod ($ start , $ interval , $ end , $ options , $ xPeriod , $ xDates )
324
+ {
325
+ if (defined ('HHVM_VERSION_ID ' ) || \PHP_VERSION_ID < 50605 ) {
326
+ $ this ->markTestSkipped ();
327
+ }
328
+
329
+ $ p = new \DatePeriod (new \DateTime ($ start ), new \DateInterval ($ interval ), is_int ($ end ) ? $ end : new \DateTime ($ end ), $ options );
330
+ $ stub = new Stub ();
331
+
332
+ $ cast = DateCaster::castPeriod ($ p , array (), $ stub , false , 0 );
333
+
334
+ $ xDump = <<<EODUMP
335
+ array:1 [
336
+ "\\x00~\\x00period" => $ xPeriod
337
+ ]
338
+ EODUMP ;
339
+
340
+ $ this ->assertDumpMatchesFormat ($ xDump , $ cast );
341
+
342
+ $ xDump = <<<EODUMP
343
+ Symfony\Component\VarDumper\Caster\ConstStub {
344
+ +type: 1
345
+ +class: " $ xPeriod"
346
+ +value: "%A $ xDates%A"
347
+ +cut: 0
348
+ +handle: 0
349
+ +refCount: 0
350
+ +position: 0
351
+ +attr: []
352
+ }
353
+ EODUMP ;
354
+
355
+ $ this ->assertDumpMatchesFormat ($ xDump , $ cast ["\0~ \0period " ]);
356
+ }
357
+
358
+ public function providePeriods ()
359
+ {
360
+ $ i = new \DateInterval ('PT0S ' );
361
+ $ ms = \PHP_VERSION_ID >= 70100 && isset ($ i ->f ) ? '.0 ' : '' ;
362
+
363
+ $ periods = array (
364
+ array ('2017-01-01 ' , 'P1D ' , '2017-01-03 ' , 0 , 'every + 1d, from 2017-01-01 00:00:00 (included) to 2017-01-03 00:00:00 ' , '1) 2017-01-01%a2) 2017-01-02 ' ),
365
+ array ('2017-01-01 ' , 'P1D ' , 1 , 0 , 'every + 1d, from 2017-01-01 00:00:00 (included) recurring 2 time/s ' , '1) 2017-01-01%a2) 2017-01-02 ' ),
366
+
367
+ array ('2017-01-01 ' , 'P1D ' , '2017-01-04 ' , 0 , 'every + 1d, from 2017-01-01 00:00:00 (included) to 2017-01-04 00:00:00 ' , '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03 ' ),
368
+ array ('2017-01-01 ' , 'P1D ' , 2 , 0 , 'every + 1d, from 2017-01-01 00:00:00 (included) recurring 3 time/s ' , '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03 ' ),
369
+
370
+ array ('2017-01-01 ' , 'P1D ' , '2017-01-05 ' , 0 , 'every + 1d, from 2017-01-01 00:00:00 (included) to 2017-01-05 00:00:00 ' , '1) 2017-01-01%a2) 2017-01-02%a1 more ' ),
371
+ array ('2017-01-01 ' , 'P1D ' , 3 , 0 , 'every + 1d, from 2017-01-01 00:00:00 (included) recurring 4 time/s ' , '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03%a1 more ' ),
372
+
373
+ array ('2017-01-01 ' , 'P1D ' , '2017-01-21 ' , 0 , 'every + 1d, from 2017-01-01 00:00:00 (included) to 2017-01-21 00:00:00 ' , '1) 2017-01-01%a17 more ' ),
374
+ array ('2017-01-01 ' , 'P1D ' , 19 , 0 , 'every + 1d, from 2017-01-01 00:00:00 (included) recurring 20 time/s ' , '1) 2017-01-01%a17 more ' ),
375
+
376
+ array ('2017-01-01 01:00:00 ' , 'P1D ' , '2017-01-03 01:00:00 ' , 0 , 'every + 1d, from 2017-01-01 01:00:00 (included) to 2017-01-03 01:00:00 ' , '1) 2017-01-01 01:00:00%a2) 2017-01-02 01:00:00 ' ),
377
+ array ('2017-01-01 01:00:00 ' , 'P1D ' , 1 , 0 , 'every + 1d, from 2017-01-01 01:00:00 (included) recurring 2 time/s ' , '1) 2017-01-01 01:00:00%a2) 2017-01-02 01:00:00 ' ),
378
+
379
+ array ('2017-01-01 ' , 'P1DT1H ' , '2017-01-03 ' , 0 , "every + 1d 01:00:00 $ ms, from 2017-01-01 00:00:00 (included) to 2017-01-03 00:00:00 " , '1) 2017-01-01 00:00:00%a2) 2017-01-02 01:00:00 ' ),
380
+ array ('2017-01-01 ' , 'P1DT1H ' , 1 , 0 , "every + 1d 01:00:00 $ ms, from 2017-01-01 00:00:00 (included) recurring 2 time/s " , '1) 2017-01-01 00:00:00%a2) 2017-01-02 01:00:00 ' ),
381
+
382
+ array ('2017-01-01 ' , 'P1D ' , '2017-01-04 ' , \DatePeriod::EXCLUDE_START_DATE , 'every + 1d, from 2017-01-01 00:00:00 (excluded) to 2017-01-04 00:00:00 ' , '1) 2017-01-02%a2) 2017-01-03 ' ),
383
+ array ('2017-01-01 ' , 'P1D ' , 2 , \DatePeriod::EXCLUDE_START_DATE , 'every + 1d, from 2017-01-01 00:00:00 (excluded) recurring 2 time/s ' , '1) 2017-01-02%a2) 2017-01-03 ' ),
384
+ );
385
+
386
+ if (\PHP_VERSION_ID < 70107 ) {
387
+ array_walk ($ periods , function (&$ i ) { $ i [5 ] = '' ; });
388
+ }
389
+
390
+ return $ periods ;
391
+ }
299
392
}
0 commit comments