8000 [PHPUnitBridge] Fix microtime() format · symfony/symfony@e3732b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit e3732b6

Browse files
committed
[PHPUnitBridge] Fix microtime() format
1 parent d1db71a commit e3732b6

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