Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PhpUnitBridge] ClockMock does not mock gmdate() #31093

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Symfony/Bridge/PhpUnit/ClockMock.php
Expand Up @@ -79,11 +79,20 @@ public static function date($format, $timestamp = null)
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, '\\'));
Expand Down Expand Up @@ -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
);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php
Expand Up @@ -62,4 +62,11 @@ public function testDate()
{
$this->assertSame('1234567890', date('U'));
}

public function testGmDate()
{
ClockMock::withClockMock(1555075769);

$this->assertSame('1555075769', gmdate('U'));
}
}