minor #16213 [2.3] Cherry-pick @group time-sensitive annotations (nicolas-grekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[2.3] Cherry-pick @group time-sensitive annotations

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

From 34a08464ce

Commits
-------

c9f92ba [2.3] Cherry-pick @group time-sensitive annotations
This commit is contained in:
Nicolas Grekas 2015-10-12 14:29:39 +02:00
commit bb07c761b8
13 changed files with 25 additions and 238 deletions

View File

@ -1,41 +0,0 @@
<?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\Console\Helper;
use Symfony\Component\Console\Tests;
function time()
{
return Tests\time();
}
namespace Symfony\Component\Console\Tests;
function with_clock_mock($enable = null)
{
static $enabled;
if (null === $enable) {
return $enabled;
}
$enabled = $enable;
}
function time()
{
if (!with_clock_mock()) {
return \time();
}
return $_SERVER['REQUEST_TIME'];
}

View File

@ -13,22 +13,12 @@ namespace Symfony\Component\Console\Tests\Helper;
use Symfony\Component\Console\Helper\ProgressHelper; use Symfony\Component\Console\Helper\ProgressHelper;
use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Tests;
require_once __DIR__.'/../ClockMock.php';
/**
* @group time-sensitive
*/
class ProgressHelperTest extends \PHPUnit_Framework_TestCase class ProgressHelperTest extends \PHPUnit_Framework_TestCase
{ {
protected function setUp()
{
Tests\with_clock_mock(true);
}
protected function tearDown()
{
Tests\with_clock_mock(false);
}
public function testAdvance() public function testAdvance()
{ {
$progress = new ProgressHelper(); $progress = new ProgressHelper();

View File

@ -1,88 +0,0 @@
<?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\HttpFoundationSession\Tests\Storage\Handler;
use Symfony\Component\HttpFoundation\Tests;
function time()
{
return Tests\time();
}
namespace Symfony\Component\HttpFoundationSession\Storage\Handler;
use Symfony\Component\HttpFoundation\Tests;
function time()
{
return Tests\time();
}
namespace Symfony\Component\HttpFoundationSession\Tests\Storage;
use Symfony\Component\HttpFoundation\Tests;
function time()
{
return Tests\time();
}
namespace Symfony\Component\HttpFoundationSession\Storage;
use Symfony\Component\HttpFoundation\Tests;
function time()
{
return Tests\time();
}
namespace Symfony\Component\HttpFoundation;
function time()
{
return Tests\time();
}
namespace Symfony\Component\HttpFoundation\Tests;
function with_clock_mock($enable = null)
{
static $enabled;
if (null === $enable) {
return $enabled;
}
$enabled = $enable;
}
function time()
{
if (!with_clock_mock()) {
return \time();
}
return $_SERVER['REQUEST_TIME'];
}
class ClockMockTestCase extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
with_clock_mock(true);
}
protected function tearDown()
{
with_clock_mock(false);
}
}

View File

@ -18,8 +18,10 @@ use Symfony\Component\HttpFoundation\Cookie;
* *
* @author John Kary <john@johnkary.net> * @author John Kary <john@johnkary.net>
* @author Hugo Hamon <hugo.hamon@sensio.com> * @author Hugo Hamon <hugo.hamon@sensio.com>
*
* @group time-sensitive
*/ */
class CookieTest extends ClockMockTestCase class CookieTest extends \PHPUnit_Framework_TestCase
{ {
public function invalidNames() public function invalidNames()
{ {

View File

@ -14,7 +14,10 @@ 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;
class ResponseHeaderBagTest extends ClockMockTestCase /**
* @group time-sensitive
*/
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @covers Symfony\Component\HttpFoundation\ResponseHeaderBag::allPreserveCase * @covers Symfony\Component\HttpFoundation\ResponseHeaderBag::allPreserveCase

View File

@ -12,12 +12,12 @@
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler;
use Symfony\Component\HttpFoundation\Tests\ClockMockTestCase;
/** /**
* @requires extension memcache * @requires extension memcache
* @group time-sensitive
*/ */
class MemcacheSessionHandlerTest extends ClockMockTestCase class MemcacheSessionHandlerTest extends \PHPUnit_Framework_TestCase
{ {
const PREFIX = 'prefix_'; const PREFIX = 'prefix_';
const TTL = 1000; const TTL = 1000;

View File

@ -12,12 +12,12 @@
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler;
use Symfony\Component\HttpFoundation\Tests\ClockMockTestCase;
/** /**
* @requires extension memcached * @requires extension memcached
* @group time-sensitive
*/ */
class MemcachedSessionHandlerTest extends ClockMockTestCase class MemcachedSessionHandlerTest extends \PHPUnit_Framework_TestCase
{ {
const PREFIX = 'prefix_'; const PREFIX = 'prefix_';
const TTL = 1000; const TTL = 1000;

View File

@ -12,13 +12,13 @@
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler;
use Symfony\Component\HttpFoundation\Tests\ClockMockTestCase;
/** /**
* @author Markus Bachmann <markus.bachmann@bachi.biz> * @author Markus Bachmann <markus.bachmann@bachi.biz>
* @requires extension mongo * @requires extension mongo
* @group time-sensitive
*/ */
class MongoDbSessionHandlerTest extends ClockMockTestCase class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var \PHPUnit_Framework_MockObject_MockObject * @var \PHPUnit_Framework_MockObject_MockObject

View File

@ -12,12 +12,12 @@
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
use Symfony\Component\HttpFoundation\Tests\ClockMockTestCase;
/** /**
* @requires extension pdo_sqlite * @requires extension pdo_sqlite
* @group time-sensitive
*/ */
class PdoSessionHandlerTest extends ClockMockTestCase class PdoSessionHandlerTest extends \PHPUnit_Framework_TestCase
{ {
private $pdo; private $pdo;

View File

@ -12,12 +12,13 @@
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage; namespace Symfony\Component\HttpFoundation\Tests\Session\Storage;
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag; use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
use Symfony\Component\HttpFoundation\Tests\ClockMockTestCase;
/** /**
* Test class for MetadataBag. * Test class for MetadataBag.
*
* @group time-sensitive
*/ */
class MetadataBagTest extends ClockMockTestCase class MetadataBagTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var MetadataBag * @var MetadataBag

View File

@ -1,60 +0,0 @@
<?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 with_clock_mock($enable = null)
{
static $enabled;
if (null === $enable) {
return $enabled;
}
$enabled = $enable;
}
function usleep($us)
{
static $now;
if (!with_clock_mock()) {
\usleep($us);
return;
}
if (null === $now) {
$now = \microtime(true);
}
return $now += $us / 1000000;
}
function microtime($asFloat = false)
{
if (!with_clock_mock()) {
return \microtime($asFloat);
}
if (!$asFloat) {
return \microtime(false);
}
return usleep(1);
}

View File

@ -13,27 +13,17 @@ namespace Symfony\Component\Stopwatch\Tests;
use Symfony\Component\Stopwatch\StopwatchEvent; use Symfony\Component\Stopwatch\StopwatchEvent;
require_once __DIR__.'/ClockMock.php';
/** /**
* StopwatchEventTest. * StopwatchEventTest.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @group time-sensitive
*/ */
class StopwatchEventTest extends \PHPUnit_Framework_TestCase class StopwatchEventTest extends \PHPUnit_Framework_TestCase
{ {
const DELTA = 37; const DELTA = 37;
protected function setUp()
{
with_clock_mock(true);
}
protected function tearDown()
{
with_clock_mock(false);
}
public function testGetOrigin() public function testGetOrigin()
{ {
$event = new StopwatchEvent(12); $event = new StopwatchEvent(12);

View File

@ -13,27 +13,17 @@ namespace Symfony\Component\Stopwatch\Tests;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
require_once __DIR__.'/ClockMock.php';
/** /**
* StopwatchTest. * StopwatchTest.
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*
* @group time-sensitive
*/ */
class StopwatchTest extends \PHPUnit_Framework_TestCase class StopwatchTest extends \PHPUnit_Framework_TestCase
{ {
const DELTA = 20; const DELTA = 20;
protected function setUp()
{
with_clock_mock(true);
}
protected function tearDown()
{
with_clock_mock(false);
}
public function testStart() public function testStart()
{ {
$stopwatch = new Stopwatch(); $stopwatch = new Stopwatch();