mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Extending TextReporter from SimpleTest to provide memory usage and execution time information for text output test results.
This commit is contained in:
parent
ad8cba41e6
commit
bed9b6e58d
3 changed files with 63 additions and 2 deletions
60
cake/tests/lib/cake_text_reporter.php
Normal file
60
cake/tests/lib/cake_text_reporter.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
class CakeTextReporter extends TextReporter {
|
||||||
|
|
||||||
|
var $_timeStart = 0;
|
||||||
|
var $_timeEnd = 0;
|
||||||
|
var $_timeDuration = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signals / Paints the beginning of a TestSuite executing.
|
||||||
|
* Starts the timer for the TestSuite execution time.
|
||||||
|
*
|
||||||
|
* @param
|
||||||
|
* @return void
|
||||||
|
**/
|
||||||
|
function paintGroupStart($test_name, $size) {
|
||||||
|
if (empty($this->_timeStart)) {
|
||||||
|
$this->_timeStart = $this->_getTime();
|
||||||
|
}
|
||||||
|
parent::paintGroupStart($test_name, $size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signals/Paints the end of a TestSuite. All test cases have run
|
||||||
|
* and timers are stopped.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
**/
|
||||||
|
function paintGroupEnd($test_name) {
|
||||||
|
$this->_timeEnd = $this->_getTime();
|
||||||
|
$this->_timeDuration = $this->_timeEnd - $this->_timeStart;
|
||||||
|
parent::paintGroupEnd($test_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current time in microseconds. Similar to getMicrotime in basics.php
|
||||||
|
* but in a separate function to reduce dependancies.
|
||||||
|
*
|
||||||
|
* @return float Time in microseconds
|
||||||
|
**/
|
||||||
|
function _getTime() {
|
||||||
|
list($usec, $sec) = explode(' ', microtime());
|
||||||
|
return ((float)$sec + (float)$usec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paints the end of the test with a summary of
|
||||||
|
* the passes and failures.
|
||||||
|
*
|
||||||
|
* @param string $test_name Name class of test.
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function paintFooter($test_name) {
|
||||||
|
parent::paintFooter($test_name);
|
||||||
|
echo 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
|
||||||
|
if (function_exists('memory_get_peak_usage')) {
|
||||||
|
echo 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -637,7 +637,8 @@ if (function_exists('caketestsgetreporter')) {
|
||||||
$Reporter =& new CakeHtmlReporter();
|
$Reporter =& new CakeHtmlReporter();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$Reporter =& new TextReporter();
|
require_once CAKE_TESTS_LIB . 'cake_text_reporter.php';
|
||||||
|
$Reporter =& new CakeTextReporter();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue