@@ -295,4 +295,65 @@ public function testGetIntersectionInvalidParams(): void
295295
296296 $ aRange ->getIntersectionWith ($ bRange );
297297 }
298+
299+ /**
300+ * @dataProvider providerWithStart
301+ */
302+ public function testWithStart (string $ originalRange , string $ start , ?string $ expectedRange ): void
303+ {
304+ $ originalRange = LocalDateRange::parse ($ originalRange );
305+
306+ if ($ expectedRange === null ) {
307+ $ this ->expectException (DateTimeException::class);
308+ }
309+
310+ $ actualRange = $ originalRange ->withStart (LocalDate::parse ($ start ));
311+
312+ if ($ expectedRange !== null ) {
313+ $ this ->assertSame ($ expectedRange , (string ) $ actualRange );
314+ }
315+ }
316+
317+ public function providerWithStart (): array
318+ {
319+ return [
320+ ['2021-06-15/2021-07-07 ' , '2021-05-29 ' , '2021-05-29/2021-07-07 ' ],
321+ ['2021-06-15/2021-07-07 ' , '2021-06-14 ' , '2021-06-14/2021-07-07 ' ],
322+ ['2021-06-15/2021-07-07 ' , '2021-06-15 ' , '2021-06-15/2021-07-07 ' ],
323+ ['2021-06-15/2021-07-07 ' , '2021-06-16 ' , '2021-06-16/2021-07-07 ' ],
324+ ['2021-06-15/2021-07-07 ' , '2021-07-06 ' , '2021-07-06/2021-07-07 ' ],
325+ ['2021-06-15/2021-07-07 ' , '2021-07-07 ' , '2021-07-07/2021-07-07 ' ],
326+ ['2021-06-15/2021-07-07 ' , '2021-07-08 ' , null ],
327+ ];
328+ }
329+
330+ /**
331+ * @dataProvider providerWithEnd
332+ */
333+ public function testWithEnd (string $ originalRange , string $ end , ?string $ expectedRange ): void
334+ {
335+ $ originalRange = LocalDateRange::parse ($ originalRange );
336+
337+ if ($ expectedRange === null ) {
338+ $ this ->expectException (DateTimeException::class);
339+ }
340+
341+ $ actualRange = $ originalRange ->withEnd (LocalDate::parse ($ end ));
342+
343+ if ($ expectedRange !== null ) {
344+ $ this ->assertSame ($ expectedRange , (string ) $ actualRange );
345+ }
346+ }
347+
348+ public function providerWithEnd (): array
349+ {
350+ return [
351+ ['2021-06-15/2021-07-07 ' , '2021-06-14 ' , null ],
352+ ['2021-06-15/2021-07-07 ' , '2021-06-15 ' , '2021-06-15/2021-06-15 ' ],
353+ ['2021-06-15/2021-07-07 ' , '2021-06-16 ' , '2021-06-15/2021-06-16 ' ],
354+ ['2021-06-15/2021-07-07 ' , '2021-07-06 ' , '2021-06-15/2021-07-06 ' ],
355+ ['2021-06-15/2021-07-07 ' , '2021-07-07 ' , '2021-06-15/2021-07-07 ' ],
356+ ['2021-06-15/2021-07-07 ' , '2021-07-08 ' , '2021-06-15/2021-07-08 ' ],
357+ ];
358+ }
298359}
0 commit comments