summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-01-17 12:19:33 +0100
committerAndrey Andreev <narf@devilix.net>2014-01-17 12:19:33 +0100
commit6672b82087e8737b074f1b849aa77c9c761e2079 (patch)
treecddeb651f21de03003bc7ddcc31cfb9b6f586801 /tests
parente33e9c1e5f0b600c0b14558fb74cf61258f7d684 (diff)
Unit tests: Full code coverage of Benchmark class
Diffstat (limited to 'tests')
-rw-r--r--tests/codeigniter/core/Benchmark_test.php26
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php
index aff736a40..7fd0727e2 100644
--- a/tests/codeigniter/core/Benchmark_test.php
+++ b/tests/codeigniter/core/Benchmark_test.php
@@ -27,10 +27,34 @@ class Benchmark_test extends CI_TestCase {
$this->assertEmpty($this->benchmark->elapsed_time('undefined_point'));
$this->benchmark->mark('code_start');
- sleep(1);
$this->benchmark->mark('code_end');
+ // Override values, because time isn't testable, but make sure the markers were set
+ if (isset($this->benchmark->marker['code_start']) && is_float($this->benchmark->marker['code_start']))
+ {
+ $this->benchmark->marker['code_start'] = 1389956144.1944;
+ }
+
+ if (isset($this->benchmark->marker['code_end']) && is_float($this->benchmark->marker['code_end']))
+ {
+ $this->benchmark->marker['code_end'] = 1389956145.1946;
+ }
+
$this->assertEquals('1', $this->benchmark->elapsed_time('code_start', 'code_end', 0));
+ $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
+ $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 2));
+ $this->assertEquals('1.000', $this->benchmark->elapsed_time('code_start', 'code_end', 3));
+ $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end', 4));
+ $this->assertEquals('1.0002', $this->benchmark->elapsed_time('code_start', 'code_end'));
+
+ // Test with non-existing 2nd marker, but again - we need to override the value
+ $this->benchmark->elapsed_time('code_start', 'code_end2');
+ if (isset($this->benchmark->marker['code_end2']) && is_float($this->benchmark->marker['code_end2']))
+ {
+ $this->benchmark->marker['code_end2'] = 1389956146.2046;
+ }
+
+ $this->assertEquals('2.0102', $this->benchmark->elapsed_time('code_start', 'code_end2'));
}
// --------------------------------------------------------------------