File tree Expand file tree Collapse file tree 6 files changed +84
-0
lines changed Expand file tree Collapse file tree 6 files changed +84
-0
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,22 @@ function time($asFloat = false)
18
18
19
19
namespace Symfony \Component \HttpFoundation \Tests ;
20
20
21
+ function with_clock_mock ($ enable = null )
22
+ {
23
+ static $ enabled ;
24
+
25
+ if (null === $ enable ) {
26
+ return $ enabled ;
27
+ }
28
+
29
+ $ enabled = $ enable ;
30
+ }
31
+
21
32
function time ()
22
33
{
34
+ if (!with_clock_mock ()) {
35
+ return \time ();
36
+ }
37
+
23
38
return $ _SERVER ['REQUEST_TIME ' ];
24
39
}
Original file line number Diff line number Diff line change 23
23
*/
24
24
class CookieTest extends \PHPUnit_Framework_TestCase
25
25
{
26
+ public function setUp ()
27
+ {
28
+ with_clock_mock (true );
29
+ parent ::setUp ();
30
+ }
31
+
32
+ public function tearDown ()
33
+ {
34
+ with_clock_mock (false );
35
+ parent ::tearDown ();
36
+ }
37
+
26
38
public function invalidNames ()
27
39
{
28
40
return array (
Original file line number Diff line number Diff line change 18
18
19
19
class ResponseHeaderBagTest extends \PHPUnit_Framework_TestCase
20
20
{
21
+ public function setUp ()
22
+ {
23
+ with_clock_mock (true );
24
+ parent ::setUp ();
25
+ }
26
+
27
+ public function tearDown ()
28
+ {
29
+ with_clock_mock (false );
30
+ parent ::tearDown ();
31
+ }
32
+
21
33
/**
22
34
* @covers Symfony\Component\HttpFoundation\ResponseHeaderBag::allPreserveCase
23
35
* @dataProvider provideAllPreserveCase
Original file line number Diff line number Diff line change @@ -18,10 +18,27 @@ function microtime($asFloat = false)
18
18
19
19
namespace Symfony \Component \Stopwatch \Tests ;
20
20
21
+ function with_clock_mock ($ enable = null )
22
+ {
23
+ static $ enabled ;
24
+
25
+ if (null === $ enable ) {
26
+ return $ enabled ;
27
+ }
28
+
29
+ $ enabled = $ enable ;
30
+ }
31
+
21
32
function usleep ($ us )
22
33
{
23
34
static $ now ;
24
35
36
+ if (!with_clock_mock ()) {
37
+ \usleep ($ us );
38
+
39
+ return ;
40
+ }
41
+
25
42
if (null === $ now ) {
26
43
$ now = \microtime (true );
27
44
}
@@ -31,6 +48,10 @@ function usleep($us)
31
48
32
49
function microtime ($ asFloat = false )
33
50
{
51
+ if (!with_clock_mock ()) {
52
+ return \microtime ($ asFloat );
53
+ }
54
+
34
55
if (!$ asFloat ) {
35
56
return \microtime (false );
36
57
}
Original file line number Diff line number Diff line change @@ -24,6 +24,18 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
24
24
{
25
25
const DELTA = 37 ;
26
26
27
+ public function setUp ()
28
+ {
29
+ with_clock_mock (true );
30
+ parent ::setUp ();
31
+ }
32
+
33
+ public function tearDown ()
34
+ {
35
+ with_clock_mock (false );
36
+ parent ::tearDown ();
37
+ }
38
+
27
39
public function testGetOrigin ()
28
40
{
29
41
$ event = new StopwatchEvent (12 );
Original file line number Diff line number Diff line change @@ -24,6 +24,18 @@ class StopwatchTest extends \PHPUnit_Framework_TestCase
24
24
{
25
25
const DELTA = 20 ;
26
26
27
+ public function setUp ()
28
+ {
29
+ with_clock_mock (true );
30
+ parent ::setUp ();
31
+ }
32
+
33
+ public function tearDown ()
34
+ {
35
+ with_clock_mock (false );
36
+ parent ::tearDown ();
37
+ }
38
+
27
39
public function testStart ()
28
40
{
29
41
$ stopwatch = new Stopwatch ();
You can’t perform that action at this time.
0 commit comments