Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/timing #1273

Merged
merged 2 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 34 additions & 27 deletions tests/system/Debug/TimerTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?php namespace CodeIgniter\Debug;
<?php
namespace CodeIgniter\Debug;

class TimerTest extends \CIUnitTestCase
{

public function setUp() { }
public function setUp()
{

}

//--------------------------------------------------------------------

public function tearDown() { }
public function tearDown()
{

}

//--------------------------------------------------------------------

Expand Down Expand Up @@ -83,38 +90,38 @@ public function testThrowsExceptionStoppingNonTimer()

//--------------------------------------------------------------------

public function testLongExecutionTime()
{
$timer = new Timer();
public function testLongExecutionTime()
{
$timer = new Timer();

$timer->start('longjohn', strtotime('-11 minutes'));
$timer->start('longjohn', strtotime('-11 minutes'));

// Use floor here to account for fractional differences in seconds.
$this->assertEquals(11 * 60, (int)$timer->getElapsedTime('longjohn'));
}
// Use floor here to account for fractional differences in seconds.
$this->assertEquals(11 * 60, (int) floor($timer->getElapsedTime('longjohn')));
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------

public function testLongExecutionTimeThroughCommonFunc()
{
timer()->start('longjohn', strtotime('-11 minutes'));
public function testLongExecutionTimeThroughCommonFunc()
{
timer()->start('longjohn', strtotime('-11 minutes'));

// Use floor here to account for fractional differences in seconds.
$this->assertEquals(11 * 60, (int)timer()->getElapsedTime('longjohn'));
}
// Use floor here to account for fractional differences in seconds.
$this->assertEquals(11 * 60, (int) floor(timer()->getElapsedTime('longjohn')));
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------

public function testCommonStartStop()
{
timer('test1');
sleep(1);
timer('test1');
public function testCommonStartStop()
{
timer('test1');
sleep(1);
timer('test1');

$this->assertGreaterThanOrEqual(1.0, timer()->getElapsedTime('test1'));
}
$this->assertGreaterThanOrEqual(1.0, timer()->getElapsedTime('test1'));
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------

public function testReturnsNullGettingElapsedTimeOfNonTimer()
{
Expand All @@ -123,5 +130,5 @@ public function testReturnsNullGettingElapsedTimeOfNonTimer()
$this->assertNull($timer->getElapsedTime('test1'));
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------
}
16 changes: 8 additions & 8 deletions tests/system/I18n/TimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public function setUp()

public function testNewTimeNow()
{
$time = new Time(null, 'America/Chicago');

$formatter = new IntlDateFormatter(
'en_US',
IntlDateFormatter::SHORT,
Expand All @@ -25,13 +23,13 @@ public function testNewTimeNow()
'yyyy-MM-dd HH:mm:ss'
);

$time = new Time(null, 'America/Chicago');

$this->assertEquals($formatter->format(strtotime('now')), (string)$time);
}

public function testTimeWithTimezone()
{
$time = new Time('now', 'Europe/London');

$formatter = new IntlDateFormatter(
'en_US',
IntlDateFormatter::SHORT,
Expand All @@ -41,13 +39,13 @@ public function testTimeWithTimezone()
'yyyy-MM-dd HH:mm:ss'
);

$time = new Time('now', 'Europe/London');

$this->assertEquals($formatter->format(strtotime('now')), (string)$time);
}

public function testTimeWithTimezoneAndLocale()
{
$time = new Time('now', 'Europe/London', 'fr_FR');

$formatter = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::SHORT,
Expand All @@ -57,13 +55,13 @@ public function testTimeWithTimezoneAndLocale()
'yyyy-MM-dd HH:mm:ss'
);

$time = new Time('now', 'Europe/London', 'fr_FR');

$this->assertEquals($formatter->format(strtotime('now')), (string)$time);
}

public function testTimeWithDateTimeZone()
{
$time = new Time('now', new \DateTimeZone('Europe/London'), 'fr_FR');

$formatter = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::SHORT,
Expand All @@ -73,6 +71,8 @@ public function testTimeWithDateTimeZone()
'yyyy-MM-dd HH:mm:ss'
);

$time = new Time('now', new \DateTimeZone('Europe/London'), 'fr_FR');

$this->assertEquals($formatter->format(strtotime('now')), (string)$time);
}

Expand Down