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
This commit is contained in:
commit
6bcdee057e
24
src/Symfony/Component/HttpFoundation/Tests/ClockMock.php
Normal file
24
src/Symfony/Component/HttpFoundation/Tests/ClockMock.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?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\Component\HttpFoundation;
|
||||||
|
|
||||||
|
function time($asFloat = false)
|
||||||
|
{
|
||||||
|
return Tests\time();
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Symfony\Component\HttpFoundation\Tests;
|
||||||
|
|
||||||
|
function time()
|
||||||
|
{
|
||||||
|
return $_SERVER['REQUEST_TIME'];
|
||||||
|
}
|
@ -13,6 +13,8 @@ namespace Symfony\Component\HttpFoundation\Tests;
|
|||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Cookie;
|
use Symfony\Component\HttpFoundation\Cookie;
|
||||||
|
|
||||||
|
require_once __DIR__.'/ClockMock.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CookieTest.
|
* CookieTest.
|
||||||
*
|
*
|
||||||
|
@ -14,6 +14,8 @@ namespace Symfony\Component\HttpFoundation\Tests;
|
|||||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||||
use Symfony\Component\HttpFoundation\Cookie;
|
use Symfony\Component\HttpFoundation\Cookie;
|
||||||
|
|
||||||
|
require_once __DIR__.'/ClockMock.php';
|
||||||
|
|
||||||
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
39
src/Symfony/Component/Stopwatch/Tests/ClockMock.php
Normal file
39
src/Symfony/Component/Stopwatch/Tests/ClockMock.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?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\Component\Stopwatch;
|
||||||
|
|
||||||
|
function microtime($asFloat = false)
|
||||||
|
{
|
||||||
|
return Tests\microtime($asFloat);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Symfony\Component\Stopwatch\Tests;
|
||||||
|
|
||||||
|
function usleep($us)
|
||||||
|
{
|
||||||
|
static $now;
|
||||||
|
|
||||||
|
if (null === $now) {
|
||||||
|
$now = \microtime(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $now += $us / 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
function microtime($asFloat = false)
|
||||||
|
{
|
||||||
|
if (!$asFloat) {
|
||||||
|
return \microtime(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return usleep(1);
|
||||||
|
}
|
@ -13,6 +13,8 @@ namespace Symfony\Component\Stopwatch\Tests;
|
|||||||
|
|
||||||
use Symfony\Component\Stopwatch\StopwatchEvent;
|
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||||
|
|
||||||
|
require_once __DIR__.'/ClockMock.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StopwatchEventTest.
|
* StopwatchEventTest.
|
||||||
*
|
*
|
||||||
|
@ -13,6 +13,8 @@ namespace Symfony\Component\Stopwatch\Tests;
|
|||||||
|
|
||||||
use Symfony\Component\Stopwatch\Stopwatch;
|
use Symfony\Component\Stopwatch\Stopwatch;
|
||||||
|
|
||||||
|
require_once __DIR__.'/ClockMock.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StopwatchTest.
|
* StopwatchTest.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user