[PhpUnitBridge] ClockMock does not mock gmdate()

This commit is contained in:
Amrouche Hamza 2019-04-12 15:32:58 +02:00
parent 2f73c2f66b
commit b34738bba6
No known key found for this signature in database
GPG Key ID: 3B02ADABCFCB29E3
2 changed files with 21 additions and 1 deletions

View File

@ -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
);
}

View File

@ -62,4 +62,11 @@ class ClockMockTest extends TestCase
{
$this->assertSame('1234567890', date('U'));
}
public function testGmDate()
{
ClockMock::withClockMock(1555075769);
$this->assertSame('1555075769', gmdate('U'));
}
}