Skip to content

Commit 7b45d8d

Browse files
authored
Merge pull request #1273 from jim-parry/fix/timing
Fix/timing
2 parents adc5717 + c91b9b1 commit 7b45d8d

2 files changed

Lines changed: 42 additions & 35 deletions

File tree

tests/system/Debug/TimerTest.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
<?php namespace CodeIgniter\Debug;
1+
<?php
2+
namespace CodeIgniter\Debug;
23

34
class TimerTest extends \CIUnitTestCase
45
{
56

6-
public function setUp() { }
7+
public function setUp()
8+
{
9+
10+
}
711

812
//--------------------------------------------------------------------
913

10-
public function tearDown() { }
14+
public function tearDown()
15+
{
16+
17+
}
1118

1219
//--------------------------------------------------------------------
1320

@@ -83,38 +90,38 @@ public function testThrowsExceptionStoppingNonTimer()
8390

8491
//--------------------------------------------------------------------
8592

86-
public function testLongExecutionTime()
87-
{
88-
$timer = new Timer();
93+
public function testLongExecutionTime()
94+
{
95+
$timer = new Timer();
8996

90-
$timer->start('longjohn', strtotime('-11 minutes'));
97+
$timer->start('longjohn', strtotime('-11 minutes'));
9198

92-
// Use floor here to account for fractional differences in seconds.
93-
$this->assertEquals(11 * 60, (int)$timer->getElapsedTime('longjohn'));
94-
}
99+
// Use floor here to account for fractional differences in seconds.
100+
$this->assertEquals(11 * 60, (int) floor($timer->getElapsedTime('longjohn')));
101+
}
95102

96-
//--------------------------------------------------------------------
103+
//--------------------------------------------------------------------
97104

98-
public function testLongExecutionTimeThroughCommonFunc()
99-
{
100-
timer()->start('longjohn', strtotime('-11 minutes'));
105+
public function testLongExecutionTimeThroughCommonFunc()
106+
{
107+
timer()->start('longjohn', strtotime('-11 minutes'));
101108

102-
// Use floor here to account for fractional differences in seconds.
103-
$this->assertEquals(11 * 60, (int)timer()->getElapsedTime('longjohn'));
104-
}
109+
// Use floor here to account for fractional differences in seconds.
110+
$this->assertEquals(11 * 60, (int) floor(timer()->getElapsedTime('longjohn')));
111+
}
105112

106-
//--------------------------------------------------------------------
113+
//--------------------------------------------------------------------
107114

108-
public function testCommonStartStop()
109-
{
110-
timer('test1');
111-
sleep(1);
112-
timer('test1');
115+
public function testCommonStartStop()
116+
{
117+
timer('test1');
118+
sleep(1);
119+
timer('test1');
113120

114-
$this->assertGreaterThanOrEqual(1.0, timer()->getElapsedTime('test1'));
115-
}
121+
$this->assertGreaterThanOrEqual(1.0, timer()->getElapsedTime('test1'));
122+
}
116123

117-
//--------------------------------------------------------------------
124+
//--------------------------------------------------------------------
118125

119126
public function testReturnsNullGettingElapsedTimeOfNonTimer()
120127
{
@@ -123,5 +130,5 @@ public function testReturnsNullGettingElapsedTimeOfNonTimer()
123130
$this->assertNull($timer->getElapsedTime('test1'));
124131
}
125132

126-
//--------------------------------------------------------------------
133+
//--------------------------------------------------------------------
127134
}

tests/system/I18n/TimeTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ public function setUp()
1414

1515
public function testNewTimeNow()
1616
{
17-
$time = new Time(null, 'America/Chicago');
18-
1917
$formatter = new IntlDateFormatter(
2018
'en_US',
2119
IntlDateFormatter::SHORT,
@@ -25,13 +23,13 @@ public function testNewTimeNow()
2523
'yyyy-MM-dd HH:mm:ss'
2624
);
2725

26+
$time = new Time(null, 'America/Chicago');
27+
2828
$this->assertEquals($formatter->format(strtotime('now')), (string)$time);
2929
}
3030

3131
public function testTimeWithTimezone()
3232
{
33-
$time = new Time('now', 'Europe/London');
34-
3533
$formatter = new IntlDateFormatter(
3634
'en_US',
3735
IntlDateFormatter::SHORT,
@@ -41,13 +39,13 @@ public function testTimeWithTimezone()
4139
'yyyy-MM-dd HH:mm:ss'
4240
);
4341

42+
$time = new Time('now', 'Europe/London');
43+
4444
$this->assertEquals($formatter->format(strtotime('now')), (string)$time);
4545
}
4646

4747
public function testTimeWithTimezoneAndLocale()
4848
{
49-
$time = new Time('now', 'Europe/London', 'fr_FR');
50-
5149
$formatter = new IntlDateFormatter(
5250
'fr_FR',
5351
IntlDateFormatter::SHORT,
@@ -57,13 +55,13 @@ public function testTimeWithTimezoneAndLocale()
5755
'yyyy-MM-dd HH:mm:ss'
5856
);
5957

58+
$time = new Time('now', 'Europe/London', 'fr_FR');
59+
6060
$this->assertEquals($formatter->format(strtotime('now')), (string)$time);
6161
}
6262

6363
public function testTimeWithDateTimeZone()
6464
{
65-
$time = new Time('now', new \DateTimeZone('Europe/London'), 'fr_FR');
66-
6765
$formatter = new IntlDateFormatter(
6866
'fr_FR',
6967
IntlDateFormatter::SHORT,
@@ -73,6 +71,8 @@ public function testTimeWithDateTimeZone()
7371
'yyyy-MM-dd HH:mm:ss'
7472
);
7573

74+
$time = new Time('now', new \DateTimeZone('Europe/London'), 'fr_FR');
75+
7676
$this->assertEquals($formatter->format(strtotime('now')), (string)$time);
7777
}
7878

0 commit comments

Comments
 (0)