Tests fix clockmock

This commit is contained in:
Evgeniy Sokolov 2015-09-10 00:21:50 +02:00 committed by Fabien Potencier
parent 753d46ac03
commit 6b21752285
6 changed files with 84 additions and 0 deletions

View File

@ -18,7 +18,22 @@ function time($asFloat = false)
namespace Symfony\Component\HttpFoundation\Tests; namespace Symfony\Component\HttpFoundation\Tests;
function with_clock_mock($enable = null)
{
static $enabled;
if (null === $enable) {
return $enabled;
}
$enabled = $enable;
}
function time() function time()
{ {
if (!with_clock_mock()) {
return \time();
}
return $_SERVER['REQUEST_TIME']; return $_SERVER['REQUEST_TIME'];
} }

View File

@ -23,6 +23,18 @@ require_once __DIR__.'/ClockMock.php';
*/ */
class CookieTest extends \PHPUnit_Framework_TestCase class CookieTest extends \PHPUnit_Framework_TestCase
{ {
public function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
public function invalidNames() public function invalidNames()
{ {
return array( return array(

View File

@ -18,6 +18,18 @@ require_once __DIR__.'/ClockMock.php';
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
{ {
public function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
/** /**
* @covers Symfony\Component\HttpFoundation\ResponseHeaderBag::allPreserveCase * @covers Symfony\Component\HttpFoundation\ResponseHeaderBag::allPreserveCase
* @dataProvider provideAllPreserveCase * @dataProvider provideAllPreserveCase

View File

@ -18,10 +18,27 @@ function microtime($asFloat = false)
namespace Symfony\Component\Stopwatch\Tests; namespace Symfony\Component\Stopwatch\Tests;
function with_clock_mock($enable = null)
{
static $enabled;
if (null === $enable) {
return $enabled;
}
$enabled = $enable;
}
function usleep($us) function usleep($us)
{ {
static $now; static $now;
if (!with_clock_mock()) {
\usleep($us);
return;
}
if (null === $now) { if (null === $now) {
$now = \microtime(true); $now = \microtime(true);
} }
@ -31,6 +48,10 @@ function usleep($us)
function microtime($asFloat = false) function microtime($asFloat = false)
{ {
if (!with_clock_mock()) {
return \microtime($asFloat);
}
if (!$asFloat) { if (!$asFloat) {
return \microtime(false); return \microtime(false);
} }

View File

@ -24,6 +24,18 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
{ {
const DELTA = 37; const DELTA = 37;
public function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
public function testGetOrigin() public function testGetOrigin()
{ {
$event = new StopwatchEvent(12); $event = new StopwatchEvent(12);

View File

@ -24,6 +24,18 @@ class StopwatchTest extends \PHPUnit_Framework_TestCase
{ {
const DELTA = 20; const DELTA = 20;
public function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
public function testStart() public function testStart()
{ {
$stopwatch = new Stopwatch(); $stopwatch = new Stopwatch();