From 6672b82087e8737b074f1b849aa77c9c761e2079 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 17 Jan 2014 13:19:33 +0200 Subject: Unit tests: Full code coverage of Benchmark class --- tests/codeigniter/core/Benchmark_test.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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')); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b