@@ -308,4 +308,97 @@ public function provideTimeZones()
308
308
array ('Pacific/Tahiti ' , 'Pacific/Tahiti (-10:00) ' , $ xRegion ),
309
309
);
310
310
}
311
+
312
+ /**
313
+ * @dataProvider providePeriods
314
+ */
315
+ public function testDumpPeriod ($ start , $ interval , $ end , $ options , $ expected )
316
+ {
317
+ if (defined ('HHVM_VERSION_ID ' ) || \PHP_VERSION_ID < 50605 ) {
318
+ $ this ->markTestSkipped ();
319
+ }
320
+
321
+ $ p = new \DatePeriod (new \DateTime ($ start ), new \DateInterval ($ interval ), is_int ($ end ) ? $ end : new \DateTime ($ end ), $ options );
322
+
323
+ $ xDump = <<<EODUMP
324
+ DatePeriod {
325
+ period: $ expected
326
+ %A}
327
+ EODUMP ;
328
+
329
+ $ this ->assertDumpMatchesFormat ($ xDump , $ p );
330
+ }
331
+
332
+ /**
333
+ * @dataProvider providePeriods
334
+ */
335
+ public function testCastPeriod ($ start , $ interval , $ end , $ options , $ xPeriod , $ xDates )
336
+ {
337
+ if (defined ('HHVM_VERSION_ID ' ) || \PHP_VERSION_ID < 50605 ) {
338
+ $ this ->markTestSkipped ();
339
+ }
340
+
341
+ $ p = new \DatePeriod (new \DateTime ($ start ), new \DateInterval ($ interval ), is_int ($ end ) ? $ end : new \DateTime ($ end ), $ options );
342
+ $ stub = new Stub ();
343
+
344
+ $ cast = DateCaster::castPeriod ($ p , array (), $ stub , false , 0 );
345
+
346
+ $ xDump = <<<EODUMP
347
+ array:1 [
348
+ "\\x00~\\x00period" => $ xPeriod
349
+ ]
350
+ EODUMP ;
351
+
352
+ $ this ->assertDumpMatchesFormat ($ xDump , $ cast );
353
+
354
+ $ xDump = <<<EODUMP
355
+ Symfony\Component\VarDumper\Caster\ConstStub {
356
+ +type: 1
357
+ +class: " $ xPeriod"
358
+ +value: "%A $ xDates%A"
359
+ +cut: 0
360
+ +handle: 0
361
+ +refCount: 0
362
+ +position: 0
363
+ +attr: []
364
+ }
365
+ EODUMP ;
366
+
367
+ $ this ->assertDumpMatchesFormat ($ xDump , $ cast ["\0~ \0period " ]);
368
+ }
369
+
370
+ public function providePeriods ()
371
+ {
372
+ $ i = new \DateInterval ('PT0S ' );
373
+ $ ms = \PHP_VERSION_ID >= 70100 && isset ($ i ->f ) ? '.0 ' : '' ;
374
+
375
+ $ periods = array (
376
+ 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 ' ),
377
+ 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 ' ),
378
+
379
+ 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 ' ),
380
+ 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 ' ),
381
+
382
+ 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 ' ),
383
+ 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 ' ),
384
+
385
+ 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 ' ),
386
+ 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 ' ),
387
+
388
+ 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 ' ),
389
+ 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 ' ),
390
+
391
+ 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 ' ),
392
+ 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 ' ),
393
+
394
+ 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 ' ),
395
+ 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 ' ),
396
+ );
397
+
398
+ if (\PHP_VERSION_ID < 70107 ) {
399
+ array_walk ($ periods , function (&$ i ) { $ i [5 ] = '' ; });
400
+ }
401
+
402
+ return $ periods ;
403
+ }
311
404
}
0 commit comments