You are here

function BootstrapTimerTestCase::testTimer in SimpleTest 7

Test timer_read() to ensure it properly accumulates time when the timer started and stopped multiple times.

File

tests/bootstrap.test, line 329

Class

BootstrapTimerTestCase

Code

function testTimer() {
  timer_start('test');
  sleep(1);
  $this
    ->assertTrue(timer_read('test') >= 1000, t('Timer measured 1 second of sleeping while running.'));
  sleep(1);
  timer_stop('test');
  $this
    ->assertTrue(timer_read('test') >= 2000, t('Timer measured 2 seconds of sleeping after being stopped.'));
  timer_start('test');
  sleep(1);
  $this
    ->assertTrue(timer_read('test') >= 3000, t('Timer measured 3 seconds of sleeping after being restarted.'));
  sleep(1);
  $timer = timer_stop('test');
  $this
    ->assertTrue(timer_read('test') >= 4000, t('Timer measured 4 seconds of sleeping after being stopped for a second time.'));
  $this
    ->assertEqual($timer['count'], 2, t('Timer counted 2 instances of being started.'));
}