Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6bcdee0

Browse files
committed
minor #15166 Mock microtime() and time() in transient tests (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- Mock microtime() and time() in transient tests | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 8319ca3 Mock microtime() and time() in transient tests
2 parents f082cd3 + 8319ca3 commit 6bcdee0

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Component\HttpFoundation;
13+
14+
function time($asFloat = false)
15+
{
16+
return Tests\time();
17+
}
18+
19+
namespace Symfony\Component\HttpFoundation\Tests;
20+
21+
function time()
22+
{
23+
return $_SERVER['REQUEST_TIME'];
24+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\HttpFoundation\Cookie;
1515

16+
require_once __DIR__.'/ClockMock.php';
17+
1618
/**
1719
* CookieTest.
1820
*

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
1515
use Symfony\Component\HttpFoundation\Cookie;
1616

17+
require_once __DIR__.'/ClockMock.php';
18+
1719
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
1820
{
1921
/**
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Component\Stopwatch;
13+
14+
function microtime($asFloat = false)
15+
{
16+
return Tests\microtime($asFloat);
17+
}
18+
19+
namespace Symfony\Component\Stopwatch\Tests;
20+
21+
function usleep($us)
22+
{
23+
static $now;
24+
25+
if (null === $now) {
26+
$now = \microtime(true);
27+
}
28+
29+
return $now += $us / 1000000;
30+
}
31+
32+
function microtime($asFloat = false)
33+
{
34+
if (!$asFloat) {
35+
return \microtime(false);
36+
}
37+
38+
return usleep(1);
39+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Stopwatch\StopwatchEvent;
1515

16+
require_once __DIR__.'/ClockMock.php';
17+
1618
/**
1719
* StopwatchEventTest.
1820
*

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Stopwatch\Stopwatch;
1515

16+
require_once __DIR__.'/ClockMock.php';
17+
1618
/**
1719
* StopwatchTest.
1820
*

0 commit comments

Comments
 (0)