File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed
src/Symfony/Bridge/PhpUnit Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 11CHANGELOG
22=========
33
4+ 7.4
5+ ---
6+
7+ * Add support for mocking the ` strtotime() ` function
8+
497.3
510---
611
Original file line number Diff line number Diff line change @@ -109,6 +109,18 @@ public static function hrtime($asNumber = false)
109109 return [(int ) self ::$ now , (int ) $ ns ];
110110 }
111111
112+ /**
113+ * @return false|int
114+ */
115+ public static function strtotime (string $ datetime , ?int $ timestamp = null )
116+ {
117+ if (null === $ timestamp ) {
118+ $ timestamp = self ::time ();
119+ }
120+
121+ return \strtotime ($ datetime , $ timestamp );
122+ }
123+
112124 public static function register ($ class ): void
113125 {
114126 $ self = static ::class;
@@ -161,6 +173,11 @@ function hrtime(\$asNumber = false)
161173{
162174 return \\ $ self::hrtime( \$asNumber);
163175}
176+
177+ function strtotime( \$datetime, \$timestamp = null)
178+ {
179+ return \\ $ self::strtotime( \$datetime, \$timestamp);
180+ }
164181EOPHP
165182 );
166183 }
Original file line number Diff line number Diff line change @@ -79,4 +79,9 @@ public function testHrTimeAsNumber()
7979 {
8080 $ this ->assertSame (1234567890125000000 , hrtime (true ));
8181 }
82+
83+ public function testStrToTime ()
84+ {
85+ $ this ->assertSame (1234567890 , strtotime ('now ' ));
86+ }
8287}
You can’t perform that action at this time.
0 commit comments