diff --git a/src/Symfony/Component/Console/Tests/ClockMock.php b/src/Symfony/Component/Console/Tests/ClockMock.php new file mode 100644 index 0000000000..0e9231662e --- /dev/null +++ b/src/Symfony/Component/Console/Tests/ClockMock.php @@ -0,0 +1,41 @@ + + * + * 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']; +} diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php index 2d2ec82b12..785fa31b7b 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php @@ -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(); diff --git a/src/Symfony/Component/HttpFoundation/Tests/ClockMock.php b/src/Symfony/Component/HttpFoundation/Tests/ClockMock.php index c74605fe95..aa954db429 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ClockMock.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ClockMock.php @@ -11,7 +11,7 @@ namespace Symfony\Component\HttpFoundation; -function time($asFloat = false) +function time() { return Tests\time(); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php index 9d794c3d6f..378e1c5c57 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php @@ -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() diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php index ef5979f1f2..161937b31d 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php @@ -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(); } /** diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php index bf5d8805ad..f67d9dc16d 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php @@ -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() diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php index 0b89f27054..b7835c6a02 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php @@ -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()