Mock microtime() and time() in transient tests

This commit is contained in:
Nicolas Grekas 2015-07-01 17:12:49 +02:00
parent 9de0d60b2c
commit 8319ca3b05
6 changed files with 71 additions and 0 deletions

View 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'];
}

View File

@ -13,6 +13,8 @@ namespace Symfony\Component\HttpFoundation\Tests;
use Symfony\Component\HttpFoundation\Cookie;
require_once __DIR__.'/ClockMock.php';
/**
* CookieTest.
*

View File

@ -14,6 +14,8 @@ namespace Symfony\Component\HttpFoundation\Tests;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Cookie;
require_once __DIR__.'/ClockMock.php';
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
{
/**

View 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);
}

View File

@ -13,6 +13,8 @@ namespace Symfony\Component\Stopwatch\Tests;
use Symfony\Component\Stopwatch\StopwatchEvent;
require_once __DIR__.'/ClockMock.php';
/**
* StopwatchEventTest.
*

View File

@ -13,6 +13,8 @@ namespace Symfony\Component\Stopwatch\Tests;
use Symfony\Component\Stopwatch\Stopwatch;
require_once __DIR__.'/ClockMock.php';
/**
* StopwatchTest.
*