Skip to content

Commit 6b21752

Browse files
ewgRafabpot
authored andcommitted
Tests fix clockmock
1 parent 753d46a commit 6b21752

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
lines changed

src/Symfony/Component/HttpFoundation/Tests/ClockMock.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,22 @@ function time($asFloat = false)
1818

1919
namespace Symfony\Component\HttpFoundation\Tests;
2020

21+
function with_clock_mock($enable = null)
22+
{
23+
static $enabled;
24+
25+
if (null === $enable) {
26+
return $enabled;
27+
}
28+
29+
$enabled = $enable;
30+
}
31+
2132
function time()
2233
{
34+
if (!with_clock_mock()) {
35+
return \time();
36+
}
37+
2338
return $_SERVER['REQUEST_TIME'];
2439
}

src/Symfony/Component/HttpFoundation/Tests/CookieTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
*/
2424
class CookieTest extends \PHPUnit_Framework_TestCase
2525
{
26+
public function setUp()
27+
{
28+
with_clock_mock(true);
29+
parent::setUp();
30+
}
31+
32+
public function tearDown()
33+
{
34+
with_clock_mock(false);
35+
parent::tearDown();
36+
}
37+
2638
public function invalidNames()
2739
{
2840
return array(

src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818

1919
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
2020
{
21+
public function setUp()
22+
{
23+
with_clock_mock(true);
24+
parent::setUp();
25+
}
26+
27+
public function tearDown()
28+
{
29+
with_clock_mock(false);
30+
parent::tearDown();
31+
}
32+
2133
/**
2234
* @covers Symfony\Component\HttpFoundation\ResponseHeaderBag::allPreserveCase
2335
* @dataProvider provideAllPreserveCase

src/Symfony/Component/Stopwatch/Tests/ClockMock.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,27 @@ function microtime($asFloat = false)
1818

1919
namespace Symfony\Component\Stopwatch\Tests;
2020

21+
function with_clock_mock($enable = null)
22+
{
23+
static $enabled;
24+
25+
if (null === $enable) {
26+
return $enabled;
27+
}
28+
29+
$enabled = $enable;
30+
}
31+
2132
function usleep($us)
2233
{
2334
static $now;
2435

36+
if (!with_clock_mock()) {
37+
\usleep($us);
38+
39+
return;
40+
}
41+
2542
if (null === $now) {
2643
$now = \microtime(true);
2744
}
@@ -31,6 +48,10 @@ function usleep($us)
3148

3249
function microtime($asFloat = false)
3350
{
51+
if (!with_clock_mock()) {
52+
return \microtime($asFloat);
53+
}
54+
3455
if (!$asFloat) {
3556
return \microtime(false);
3657
}

src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
2424
{
2525
const DELTA = 37;
2626

27+
public function setUp()
28+
{
29+
with_clock_mock(true);
30+
parent::setUp();
31+
}
32+
33+
public function tearDown()
34+
{
35+
with_clock_mock(false);
36+
parent::tearDown();
37+
}
38+
2739
public function testGetOrigin()
2840
{
2941
$event = new StopwatchEvent(12);

src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ class StopwatchTest extends \PHPUnit_Framework_TestCase
2424
{
2525
const DELTA = 20;
2626

27+
public function setUp()
28+
{
29+
with_clock_mock(true);
30+
parent::setUp();
31+
}
32+
33+
public function tearDown()
34+
{
35+
with_clock_mock(false);
36+
parent::tearDown();
37+
}
38+
2739
public function testStart()
2840
{
2941
$stopwatch = new Stopwatch();

0 commit comments

Comments
 (0)