Issue #2049817 by jhedstrom: Expand phpunit tests for \Drupal\Component\Utility\Timer.

8.0.x
webchick 2013-08-10 01:59:24 -07:00
parent 5e30494edb
commit 7a82f32a6f
1 changed files with 25 additions and 6 deletions

View File

@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Tests\Component\Utility\TimerUnitTest.
* Contains \Drupal\Tests\Component\Utility\TimerTest.
*/
namespace Drupal\Tests\Component\Utility;
@ -15,7 +15,7 @@ use Drupal\Component\Utility\Timer;
*
* @see \Drupal\Component\Utility\Timer
*/
class TimerUnitTest extends UnitTestCase {
class TimerTest extends UnitTestCase {
public static function getInfo() {
return array(
@ -46,13 +46,32 @@ class TimerUnitTest extends UnitTestCase {
// http://php.net/manual/en/function.usleep.php for more information. The
// purpose of the test to validate that the Timer class can measure elapsed
// time not the granularity of usleep() on a particular OS.
$this->assertGreaterThanOrEqual(4, $value, 'Timer measured at least 4 milliseconds of sleeping while running.');
$this->assertGreaterThanOrEqual(4, $value, 'Timer failed to measure at least 4 milliseconds of sleeping while running.');
$this->assertGreaterThanOrEqual($value + 4, $value2, 'Timer measured at least 8 milliseconds of sleeping while running.');
$this->assertGreaterThanOrEqual($value + 4, $value2, 'Timer failed to measure at least 8 milliseconds of sleeping while running.');
$this->assertGreaterThanOrEqual($value2 + 4, $value3, 'Timer measured at least 12 milliseconds of sleeping while running.');
$this->assertGreaterThanOrEqual($value2 + 4, $value3, 'Timer failed to measure at least 12 milliseconds of sleeping while running.');
$this->assertGreaterThanOrEqual($value3 + 4, $value4, 'Timer measured at least 16 milliseconds of sleeping while running.');
$this->assertGreaterThanOrEqual($value3 + 4, $value4, 'Timer failed to measure at least 16 milliseconds of sleeping while running.');
// Stop the timer.
$value5 = Timer::stop('test');
$this->assertGreaterThanOrEqual($value4, $value5['time'], 'Timer measured after stopping was not greater than last measurement.');
// Read again.
$value6 = Timer::read('test');
$this->assertEquals($value5['time'], $value6, 'Timer measured after stopping was not equal to the stopped time.');
// Restart.
Timer::start('test');
usleep(5000);
$value7 = Timer::read('test');
$this->assertGreaterThanOrEqual($value6 + 4, $value7, 'Timer failed to measure at least 16 milliseconds of sleeping while running.');
// Stop again.
$value8 = Timer::stop('test');
$value9 = Timer::read('test');
$this->assertEquals($value8['time'], $value9, 'Timer measured after stopping not equal to stop time.');
}
}