minor #15848 [Console] Add clock mock to fix transient test on HHVM (nicolas-grekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[Console] Add clock mock to fix transient test on HHVM

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

This should fix the most frequent transient test on HHVM (ProgressBarTest::testAnsiColorsAndEmojis)

Commits
-------

549f43b [Console] Add clock mock to fix transient test on HHVM
This commit is contained in:
Fabien Potencier 2015-09-21 07:58:06 +02:00
commit 451bdc0bf0
7 changed files with 63 additions and 17 deletions

View File

@ -0,0 +1,41 @@
<?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,9 +13,22 @@ namespace Symfony\Component\Console\Tests\Helper;
use Symfony\Component\Console\Helper\ProgressHelper;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Tests;
require_once __DIR__.'/../ClockMock.php';
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()
{
$progress = new ProgressHelper();

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\HttpFoundation;
function time($asFloat = false)
function time()
{
return Tests\time();
}

View File

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

View File

@ -18,16 +18,14 @@ require_once __DIR__.'/ClockMock.php';
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
protected function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
protected function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
/**

View File

@ -24,16 +24,14 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
{
const DELTA = 37;
public function setUp()
protected function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
protected function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
public function testGetOrigin()

View File

@ -24,16 +24,14 @@ class StopwatchTest extends \PHPUnit_Framework_TestCase
{
const DELTA = 20;
public function setUp()
protected function setUp()
{
with_clock_mock(true);
parent::setUp();
}
public function tearDown()
protected function tearDown()
{
with_clock_mock(false);
parent::tearDown();
}
public function testStart()