8000 feature #31093 [PhpUnitBridge] ClockMock does not mock gmdate() (Simp… · symfony/symfony@37eff9b · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 37eff9b

Browse files
feature #31093 [PhpUnitBridge] ClockMock does not mock gmdate() (Simperfit)
This PR was merged into the 4.3-dev branch. Discussion ---------- [PhpUnitBridge] ClockMock does not mock gmdate() | Q | A | ------------- | --- | Branch? | feature | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #30393 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#11418 <!-- required for new features --> <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Adding the feature to mock gmdate directly in ClockMock. Commits ------- b34738b [PhpUnitBridge] ClockMock does not mock gmdate()
2 parents 2f73c2f + b34738b commit 37eff9b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Symfony/Bridge/PhpUnit/ClockMock.php

Lines changed: 14 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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)
0