diff --git a/src/Symfony/Bridge/PhpUnit/ClockMock.php b/src/Symfony/Bridge/PhpUnit/ClockMock.php index 14b482c874..10c7d8780c 100644 --- a/src/Symfony/Bridge/PhpUnit/ClockMock.php +++ b/src/Symfony/Bridge/PhpUnit/ClockMock.php @@ -79,11 +79,20 @@ class ClockMock return \date($format, $timestamp); } + public static function gmdate($format, $timestamp = null) + { + if (null === $timestamp) { + $timestamp = self::time(); + } + + return \gmdate($format, $timestamp); + } + public static function register($class) { $self = \get_called_class(); - $mockedNs = array(substr($class, 0, strrpos($class, '\\'))); + $mockedNs = [substr($class, 0, strrpos($class, '\\'))]; if (0 < strpos($class, '\\Tests\\')) { $ns = str_replace('\\Tests\\', '\\', $class); $mockedNs[] = substr($ns, 0, strrpos($ns, '\\')); @@ -122,6 +131,10 @@ function date(\$format, \$timestamp = null) return \\$self::date(\$format, \$timestamp); } +function gmdate(\$format, \$timestamp = null) +{ + return \\$self::gmdate(\$format, \$timestamp); +} EOPHP ); } diff --git a/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php b/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php index 4c77e99f5e..5b92ccd850 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php @@ -62,4 +62,11 @@ class ClockMockTest extends TestCase { $this->assertSame('1234567890', date('U')); } + + public function testGmDate() + { + ClockMock::withClockMock(1555075769); + + $this->assertSame('1555075769', gmdate('U')); + } }