8000 bug #28648 [PHPUnitBridge] Fix ClockMock microtime() format (acasadem… · symfony/symfony@28841c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28841c4

Browse files
bug #28648 [PHPUnitBridge] Fix ClockMock microtime() format (acasademont)
This PR was merged into the 2.8 branch. Discussion ---------- [PHPUnitBridge] Fix ClockMock microtime() format | Q | A | ------------- | --- | Branch? | 2.8 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes/no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | no <!-- please add some, will be required by reviewers --> | Fixed tickets | <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | <!-- required for new features --> This is a follow-up PR to #27890 to fix the `microtime` precision, it should be 8 decimals instead of the current 6 (see https://3v4l.org/GYacF) The problem now is that due to the new tests the whole testsuite will fail if run from the main directory, as hhvm and 5.4 targets are doing, due to phpunit using the wrong `ClockMock` class. Tests for 7.1 and 7.2 pass because they `cd` into the component directory. Commits ------- e3732b6 [PHPUnitBridge] Fix microtime() format
2 parents 47f2aee + e3732b6 commit 28841c4

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/Symfony/Bridge/PhpUnit/ClockMock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function microtime($asFloat = false)
6666
return self::$now;
6767
}
6868

69-
return sprintf('%0.6f %d', self::$now - (int) self::$now, (int) self::$now);
69+
return sprintf('%0.6f00 %d', self::$now - (int) self::$now, (int) self::$now);
7070
}
7171

7272
public static function register($class)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ClockMock;
16+
17+
/**
18+
* @author Dominic Tubach <dominic.tubach@to.com>
19+
*
20+
* @covers \Symfony\Bridge\PhpUnit\ClockMock
21+
*/
22+
class ClockMockTest extends TestCase
23+
{
24+
public static function setUpBeforeClass()
25+
{
26+
ClockMock::register(__CLASS__);
27+
}
28+
29+
protected function setUp()
30+
{
31+
ClockMock::withClockMock(1234567890.125);
32+
}
33+
34+
public function testTime()
35+
{
36+
$this->assertSame(1234567890, time());
37+
}
38+
39+
public function testSleep()
40+
{
41+
sleep(2);
42+
$this->assertSame(1234567892, time());
43+
}
44+
45+
public function testMicrotime()
46+
{
47+
$this->assertSame('0.12500000 1234567890', microtime());
48+
}
49+
50+
public function testMicrotimeAsFloat()
51+
{
52+
$this->assertSame(1234567890.125, microtime(true));
53+
}
54+
55+
public function testUsleep()
56+
{
57+
usleep(2);
58+
$this->assertSame(1234567890.125002, microtime(true));
59+
}
60+
}

0 commit comments

Comments
 (0)
0