Skip to content

Commit b34738b

Browse files
author
Amrouche Hamza
committed
[PhpUnitBridge] ClockMock does not mock gmdate()
1 parent 2f73c2f commit b34738b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Symfony/Bridge/PhpUnit/ClockMock.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,20 @@ public static function date($format, $timestamp = null)
7979
return \date($format, $timestamp);
8080
}
8181

82+
public static function gmdate($format, $timestamp = null)
83+
{
84+
if (null === $timestamp) {
85+
$timestamp = self::time();
86+
}
87+
88+
return \gmdate($format, $timestamp);
89+
}
90+
8291
public static function register($class)
8392
{
8493
$self = \get_called_class();
8594

86-
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
95+
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
8796
if (0 < strpos($class, '\\Tests\\')) {
8897
$ns = str_replace('\\Tests\\', '\\', $class);
8998
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));
@@ -122,6 +131,10 @@ function date(\$format, \$timestamp = null)
122131
return \\$self::date(\$format, \$timestamp);
123132
}
124133
134+
function gmdate(\$format, \$timestamp = null)
135+
{
136+
return \\$self::gmdate(\$format, \$timestamp);
137+
}
125138
EOPHP
126139
);
127140
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,11 @@ public function testDate()
6262
{
6363
$this->assertSame('1234567890', date('U'));
6464
}
65+
66+
public function testGmDate()
67+
{
68+
ClockMock::withClockMock(1555075769);
69+
70+
$this->assertSame('1555075769', gmdate('U'));
71+
}
6572
}

0 commit comments

Comments
 (0)