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
-------
e3732b63c6
[PHPUnitBridge] Fix microtime() format
This commit is contained in:
commit
28841c4157
@ -66,7 +66,7 @@ class ClockMock
|
|||||||
return self::$now;
|
return self::$now;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sprintf('%0.6f %d', self::$now - (int) self::$now, (int) self::$now);
|
return sprintf('%0.6f00 %d', self::$now - (int) self::$now, (int) self::$now);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function register($class)
|
public static function register($class)
|
||||||
|
60
src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php
Normal file
60
src/Symfony/Bridge/PhpUnit/Tests/ClockMockTest.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\PhpUnit\Tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Bridge\PhpUnit\ClockMock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Dominic Tubach <dominic.tubach@to.com>
|
||||||
|
*
|
||||||
|
* @covers \Symfony\Bridge\PhpUnit\ClockMock
|
||||||
|
*/
|
||||||
|
class ClockMockTest extends TestCase
|
||||||
|
{
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
ClockMock::register(__CLASS__);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
ClockMock::withClockMock(1234567890.125);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTime()
|
||||||
|
{
|
||||||
|
$this->assertSame(1234567890, time());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSleep()
|
||||||
|
{
|
||||||
|
sleep(2);
|
||||||
|
$this->assertSame(1234567892, time());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMicrotime()
|
||||||
|
{
|
||||||
|
$this->assertSame('0.12500000 1234567890', microtime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMicrotimeAsFloat()
|
||||||
|
{
|
||||||
|
$this->assertSame(1234567890.125, microtime(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUsleep()
|
||||||
|
{
|
||||||
|
usleep(2);
|
||||||
|
$this->assertSame(1234567890.125002, microtime(true));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user