Skip to content
This repository
Browse code

Adding time and memory output to the test suite results.

  • Loading branch information...
commit ea7df4f7ce658625073f583cf6c6c04fa9f59faa 1 parent edf5f2d
Mark Story authored
45  cake/tests/lib/cake_reporter.php
@@ -37,6 +37,10 @@ class CakeHtmlReporter extends SimpleReporter {
37 37
 	var $_character_set;
38 38
 	var $_show_passes = false;
39 39
 
  40
+	var $_timeStart = 0;
  41
+	var $_timeEnd = 0;
  42
+	var $_timeDuration = 0;
  43
+
40 44
 /**
41 45
  * Does nothing yet. The first output will
42 46
  * be sent on the first test start. For use
@@ -53,6 +57,41 @@ function CakeHtmlReporter($character_set = 'ISO-8859-1') {
53 57
 	}
54 58
 
55 59
 /**
  60
+ * Signals / Paints the beginning of a TestSuite executing.
  61
+ * Starts the timer for the TestSuite execution time.
  62
+ *
  63
+ * @param 
  64
+ * @return void
  65
+ **/
  66
+	function paintGroupStart($test_name, $size) {
  67
+		$this->_timeStart = $this->_getTime();
  68
+		parent::paintGroupStart($test_name, $size);
  69
+	}
  70
+
  71
+/**
  72
+ * Signals/Paints the end of a TestSuite. All test cases have run
  73
+ * and timers are stopped.
  74
+ *
  75
+ * @return void
  76
+ **/
  77
+	function paintGroupEnd($test_name) {
  78
+		$this->_timeEnd = $this->_getTime();
  79
+		$this->_timeDuration = $this->_timeEnd - $this->_timeStart;
  80
+		parent::paintGroupEnd($test_name);
  81
+	}
  82
+
  83
+/**
  84
+ * Get the current time in microseconds. Similar to getMicrotime in basics.php
  85
+ * but in a separate function to reduce dependancies.
  86
+ *
  87
+ * @return float Time in microseconds
  88
+ **/
  89
+	function _getTime() {
  90
+		list($usec, $sec) = explode(' ', microtime());
  91
+		return ((float)$sec + (float)$usec);
  92
+	}
  93
+
  94
+/**
56 95
  * Paints the top of the web page setting the
57 96
  * title to the name of the starting test.
58 97
  *
@@ -102,6 +141,12 @@ function paintFooter($test_name) {
102 141
 		echo "<strong>" . $this->getFailCount() . "</strong> fails and ";
103 142
 		echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
104 143
 		echo "</div>\n";
  144
+		echo '<div style="padding:0 0 5px;">';
  145
+		echo '<p><strong>Time taken by tests (in seconds):</strong> ' . $this->_timeDuration . '</p>';
  146
+		if (function_exists('memory_get_peak_usage')) {
  147
+			echo '<p><strong>Peak memory use: (in bytes):</strong> ' . number_format(memory_get_peak_usage()) . '</p>';
  148
+		}
  149
+		echo '</div>';
105 150
 	}
106 151
 
107 152
 /**
1  cake/tests/lib/test_manager.php
@@ -619,6 +619,7 @@ function &getTestCaseList() {
619 619
 		return $buffer;
620 620
 	}
621 621
 }
  622
+
622 623
 if (function_exists('caketestsgetreporter')) {
623 624
 	echo "You need a new test.php. \n";
624 625
 	echo "Try this one: " . dirname(CONSOLE_LIBS) . "templates" . DS . "skel" . DS . "webroot" . DS . "test.php";

0 notes on commit ea7df4f

Please sign in to comment.
Something went wrong with that request. Please try again.