From e981ade94dcabbc8fd41f11fbe89b02824161f39 Mon Sep 17 00:00:00 2001 From: jprivet-dev Date: Thu, 15 May 2025 08:45:41 +0200 Subject: [PATCH 1/3] feat(ClockMock): add strtotime() --- src/Symfony/Bridge/PhpUnit/ClockMock.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/ClockMock.php b/src/Symfony/Bridge/PhpUnit/ClockMock.php index 4cca8fc26cfc6..7c76596f3a50a 100644 --- a/src/Symfony/Bridge/PhpUnit/ClockMock.php +++ b/src/Symfony/Bridge/PhpUnit/ClockMock.php @@ -109,6 +109,18 @@ public static function hrtime($asNumber = false) return [(int) self::$now, (int) $ns]; } + /** + * @return false|int + */ + public static function strtotime(string $datetime, ?int $timestamp = null) + { + if (null === $timestamp) { + $timestamp = self::time(); + } + + return \strtotime($datetime, $timestamp); + } + public static function register($class): void { $self = static::class; @@ -161,6 +173,11 @@ function hrtime(\$asNumber = false) { return \\$self::hrtime(\$asNumber); } + +function strtotime(\$datetime, \$timestamp = null) +{ + return \\$self::strtotime(\$datetime, \$timestamp); +} EOPHP ); } From 153464b3c537ade2a13c718d7922c3cd53ef28a0 Mon Sep 17 00:00:00 2001 From: jprivet-dev Date: Thu, 15 May 2025 08:46:01 +0200 Subject: [PATCH 2/3] feat(ClockMockTest): add test on strtotime() --- src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php b/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php index 7df7865d1c9be..84241081f7ba0 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php @@ -79,4 +79,9 @@ public function testHrTimeAsNumber() { $this->assertSame(1234567890125000000, hrtime(true)); } + + public function testStrToTime() + { + $this->assertSame(1234567890, strtotime('now')); + } } From 4ac21d272529b4180efe82fae1c27df2a68d3d97 Mon Sep 17 00:00:00 2001 From: jprivet-dev Date: Thu, 15 May 2025 16:07:20 +0200 Subject: [PATCH 3/3] feat(Bridge/PhpUnit/CHANGELOG): add support for mocking the strtotime function --- src/Symfony/Bridge/PhpUnit/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/CHANGELOG.md b/src/Symfony/Bridge/PhpUnit/CHANGELOG.md index 0b139af321f5d..579fd88af71cf 100644 --- a/src/Symfony/Bridge/PhpUnit/CHANGELOG.md +++ b/src/Symfony/Bridge/PhpUnit/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Add support for mocking the `strtotime()` function + 7.3 ---