8000 minor #15848 [Console] Add clock mock to fix transient test on HHVM (… · symfony/symfony@451bdc0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 451bdc0

Browse files
committed
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
2 parents e47d3f1 + 549f43b commit 451bdc0

File tree

7 files changed

+63
-17
lines changed

7 files changed

+63
-17
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Helper;
13+
14+
use Symfony\Component\Console\Tests;
15+
16+
function time()
17+
{
18+
return Tests\time();
19+
}
20+
21+
namespace Symfony\Component\Console\Tests;
22+
23+
function with_clock_mock($enable = null)
24+
{
25+
static $enabled;
26+
27+
if (null === $enable) {
28+
return $enabled;
29+
}
30+
31+
$enabled = $enable;
32+
}
33+
34+
function time()
35+
{
36+
if (!with_clock_mock()) {
37+
return \time();
38+
}
39+
40+
return $_SERVER['REQUEST_TIME'];
41+
}

src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,22 @@
1313

1414
use Symfony\Component\Console\Helper\ProgressHelper;
1515
use Symfony\Component\Console\Output\StreamOutput;
16+
use Symfony\Component\Console\Tests;
17+
18+
require_once __DIR__.'/../ClockMock.php';
1619

1720
class ProgressHelperTest extends \PHPUnit_Framework_TestCase
1821
{
22+
protected function setUp()
23+
{
24+
Tests\with_clock_mock(true);
25+
}
26+
27+
protected function tearDown()
28+
{
29+
Tests\with_clock_mock(false);
30+
}
31+
1932
public function testAdvance()
2033
{
2134
$progress = new ProgressHelper();

src/Symfony/Component/HttpFoundation/Tests/ClockMock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\HttpFoundation;
1313

14-
function time($asFloat = false)
14+
function time()
1515
{
1616
return Tests\time();
1717
}

src/Symfony/Component/HttpFoundation/Tests/CookieTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323
*/
2424
class CookieTest extends \PHPUnit_Framework_TestCase
2525
{
26-
public function setUp()
26+
protected function setUp()
2727
{
2828
with_clock_mock(true);
29-
parent::setUp();
3029
}
3130

32-
public function tearDown()
31+
protected function tearDown()
3332
{
3433
with_clock_mock(false);
35-
parent::tearDown();
3634
}
3735

3836
public function invalidNames()

src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818

1919
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
2020
{
21-
public function setUp()
21+
protected function setUp()
2222
{
2323
with_clock_mock(true);
24-
parent::setUp();
2524
}
2625

27-
public function tearDown()
26+
protected function tearDown()
2827
{
2928
with_clock_mock(false);
30-
parent::tearDown();
3129
}
3230

3331
/**

src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
2424
{
2525
const DELTA = 37;
2626

27-
public function setUp()
27+
protected function setUp()
2828
{
2929
with_clock_mock(true);
30-
parent::setUp();
3130
}
3231

33-
public function tearDown()
32+
protected function tearDown()
3433
{
3534
with_clock_mock(false);
36-
parent::tearDown();
3735
}
3836

3937
public function testGetOrigin()

src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ class StopwatchTest extends \PHPUnit_Framework_TestCase
2424
{
2525
const DELTA = 20;
2626

27-
public function setUp()
27+
protected function setUp()
2828
{
2929
with_clock_mock(true);
30-
parent::setUp();
3130
}
3231

33-
public function tearDown()
32+
protected function tearDown()
3433
{
3534
with_clock_mock(false);
36-
parent::tearDown();
3735
}
3836

3937
public function testStart()

0 commit comments

Comments
 (0)
0