@@ -63,6 +63,59 @@ public function testSleep()
63
63
$ this ->assertSame ($ tz , $ clock ->now ()->getTimezone ()->getName ());
64
64
}
65
65
66
+ public function provideValidModifyStrings (): iterable
67
+ {
68
+ yield 'absolute datetime value ' => [
69
+ '2112-09-17 23:53:03.001 ' ,
70
+ '2112-09-17 23:53:03.001000 ' ,
71
+ ];
72
+
73
+ yield 'relative modified date ' => [
74
+ '+2 days ' ,
75
+ '2112-09-19 23:53:00.999000 ' ,
76
+ ];
77
+ }
78
+
79
+ /**
80
+ * @dataProvider provideValidModifyStrings
81
+ */
82
+ public function testModifyWithSpecificDateTime (string $ modifiedNow , string $ expectedNow )
83
+ {
84
+ $ clock = new MockClock ((new \DateTimeImmutable ('2112-09-17 23:53:00.999Z ' ))->setTimezone (new \DateTimeZone ('UTC ' )));
85
+ $ tz = $ clock ->now ()->getTimezone ()->getName ();
86
+
87
+ $ clock ->modify ($ modifiedNow );
88
+
89
+ $ this ->assertSame ($ expectedNow , $ clock ->now ()->format ('Y-m-d H:i:s.u ' ));
90
+ $ this ->assertSame ($ tz , $ clock ->now ()->getTimezone ()->getName ());
91
+ }
92
+
93
+ public function provideInvalidModifyStrings (): iterable
94
+ {
95
+ yield 'Named holiday is not recognized ' => [
96
+ 'Halloween ' ,
97
+ 'Invalid modifier: "Halloween". Could not modify MockClock. ' ,
98
+ ];
99
+
100
+ yield 'empty string ' => [
101
+ '' ,
102
+ 'Invalid modifier: "". Could not modify MockClock. ' ,
103
+ ];
104
+ }
105
+
106
+ /**
107
+ * @dataProvider provideInvalidModifyStrings
108
+ */
109
+ public function testModifyThrowsOnInvalidString (string $ modifiedNow , string $ expectedMessage )
110
+ {
111
+ $ clock = new MockClock ((new \DateTimeImmutable ('2112-09-17 23:53:00.999Z ' ))->setTimezone (new \DateTimeZone ('UTC ' )));
112
+
113
+ $ this ->expectException (\InvalidArgumentException::class);
114
+ $ this ->expectExceptionMessage ($ expectedMessage );
115
+
116
+ $ clock ->modify ($ modifiedNow );
117
+ }
118
+
66
119
public function testWithTimeZone ()
67
120
{
68
121
$ clock = new MockClock ();
0 commit comments