2008-08-13 03:47:05 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Test reporter optimised for CLI (ie, plain-text) output
|
2009-03-22 23:59:14 +01:00
|
|
|
*
|
|
|
|
* @package sapphire
|
2010-04-23 03:04:16 +02:00
|
|
|
* @subpackage testing
|
2008-08-13 03:47:05 +02:00
|
|
|
*/
|
|
|
|
class CliTestReporter extends SapphireTestReporter {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display error bar if it exists
|
|
|
|
*/
|
|
|
|
public function writeResults() {
|
|
|
|
$passCount = 0;
|
|
|
|
$failCount = 0;
|
|
|
|
$testCount = 0;
|
2012-04-14 13:11:54 +02:00
|
|
|
$incompleteCount = 0;
|
2008-08-13 03:47:05 +02:00
|
|
|
$errorCount = 0;
|
2012-04-14 13:11:54 +02:00
|
|
|
|
2008-08-13 03:47:05 +02:00
|
|
|
foreach($this->suiteResults['suites'] as $suite) {
|
|
|
|
foreach($suite['tests'] as $test) {
|
|
|
|
$testCount++;
|
2012-04-14 13:11:54 +02:00
|
|
|
if($test['status'] == 2) {
|
|
|
|
$incompleteCount++;
|
|
|
|
} elseif($test['status'] === 1) {
|
|
|
|
$passCount++;
|
|
|
|
} else {
|
|
|
|
$failCount++;
|
|
|
|
}
|
2008-08-13 03:47:05 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-04 07:41:15 +02:00
|
|
|
|
|
|
|
echo "\n\n";
|
|
|
|
if ($failCount == 0) {
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
echo SS_Cli::text(" ALL TESTS PASS ", "white", "green");
|
2008-10-04 07:41:15 +02:00
|
|
|
} else {
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
echo SS_Cli::text(" AT LEAST ONE FAILURE ", "white", "red");
|
2008-10-04 07:41:15 +02:00
|
|
|
}
|
2012-04-14 13:11:54 +02:00
|
|
|
|
|
|
|
echo sprintf("\n\n%d tests run: %s, %s, and %s\n", $testCount, SS_Cli::text("$passCount passes"), SS_Cli::text("$failCount failures"), SS_Cli::text("$incompleteCount incomplete"));
|
|
|
|
|
2009-05-06 08:36:16 +02:00
|
|
|
if(function_exists('memory_get_peak_usage')) {
|
|
|
|
echo "Maximum memory usage: " . number_format(memory_get_peak_usage()/(1024*1024), 1) . "M\n\n";
|
|
|
|
}
|
2008-10-17 04:28:55 +02:00
|
|
|
|
|
|
|
// Use sake dev/tests/all --showslow to show slow tests
|
|
|
|
if((isset($_GET['args']) && is_array($_GET['args']) && in_array('--showslow', $_GET['args'])) || isset($_GET['showslow'])) {
|
|
|
|
$avgSpeed = round(array_sum($this->testSpeeds) / count($this->testSpeeds), 3);
|
2010-04-12 04:03:16 +02:00
|
|
|
echo "Slow tests (more than the average $avgSpeed seconds):\n";
|
2008-10-17 04:28:55 +02:00
|
|
|
|
|
|
|
arsort($this->testSpeeds);
|
|
|
|
foreach($this->testSpeeds as $k => $v) {
|
|
|
|
// Ignore below-average speeds
|
2010-04-12 04:03:16 +02:00
|
|
|
if($v < $avgSpeed) break;
|
2008-10-17 04:28:55 +02:00
|
|
|
|
|
|
|
echo " - $k: " . round($v,3) . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "\n";
|
2008-08-13 03:47:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function endTest( PHPUnit_Framework_Test $test, $time) {
|
2008-09-23 05:22:13 +02:00
|
|
|
// Status indicator, a la PHPUnit
|
|
|
|
switch($this->currentTest['status']) {
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
case TEST_FAILURE: echo SS_Cli::text("F","red", null, true); break;
|
|
|
|
case TEST_ERROR: echo SS_Cli::text("E","red", null, true); break;
|
|
|
|
case TEST_INCOMPLETE: echo SS_Cli::text("I","yellow"); break;
|
|
|
|
case TEST_SUCCESS: echo SS_Cli::text(".","green"); break;
|
|
|
|
default: echo SS_Cli::text("?", "yellow"); break;
|
2008-09-23 05:22:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-03 04:23:35 +02:00
|
|
|
static $colCount = 0;
|
|
|
|
$colCount++;
|
2010-10-19 02:56:25 +02:00
|
|
|
if($colCount % 80 == 0) echo " - $colCount\n";
|
2008-10-03 04:23:35 +02:00
|
|
|
|
2008-08-13 03:47:05 +02:00
|
|
|
parent::endTest($test, $time);
|
|
|
|
$this->writeTest($this->currentTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function writeTest($test) {
|
|
|
|
if ($test['status'] != 1) {
|
2008-10-09 03:45:36 +02:00
|
|
|
$filteredTrace = array();
|
|
|
|
$ignoredClasses = array('TestRunner');
|
|
|
|
foreach($test['trace'] as $item) {
|
2008-10-09 17:14:31 +02:00
|
|
|
if(
|
|
|
|
isset($item['file'])
|
|
|
|
&& strpos($item['file'], 'PHPUnit/Framework') === false
|
2008-10-09 03:45:36 +02:00
|
|
|
&& (!isset($item['class']) || !in_array($item['class'], $ignoredClasses))) {
|
|
|
|
|
|
|
|
$filteredTrace[] = $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($item['class']) && isset($item['function']) && $item['class'] == 'PHPUnit_Framework_TestSuite'
|
|
|
|
&& $item['function'] == 'run') break;
|
|
|
|
|
|
|
|
}
|
2012-04-14 13:11:54 +02:00
|
|
|
|
|
|
|
if( $test['status'] == 2) {
|
|
|
|
echo "\n" . SS_Cli::text($this->testNameToPhrase($test['name']) . "\n" . $test['message'] . "\n", 'yellow', null, true);
|
|
|
|
} else {
|
|
|
|
echo "\n" . SS_Cli::text($this->testNameToPhrase($test['name']) . "\n". $test['message'] . "\n", 'red', null, true);
|
|
|
|
echo SS_Backtrace::get_rendered_backtrace($filteredTrace, true);
|
|
|
|
}
|
2008-08-13 05:42:45 +02:00
|
|
|
echo "\n--------------------\n";
|
2008-08-13 03:47:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-14 13:11:54 +02:00
|
|
|
}
|