Skip to content

Commit 0c00ffe

Browse files
feature #60424 [PhpUnitBridge] Add strtotime() to ClockMock (jprivet-dev)
This PR was squashed before being merged into the 7.4 branch. Discussion ---------- [PhpUnitBridge] Add `strtotime()` to `ClockMock` | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | | License | MIT Commits ------- fc9491e [PhpUnitBridge] Add `strtotime()` to `ClockMock`
2 parents 33ecd1c + fc9491e commit 0c00ffe

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/Symfony/Bridge/PhpUnit/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.4
5+
---
6+
7+
* Add support for mocking the `strtotime()` function
8+
49
7.3
510
---
611

src/Symfony/Bridge/PhpUnit/ClockMock.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}
164181
EOPHP
165182
);
166183
}

src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)