Modified: php/phpruntests/trunk/src/testcase/output/rtTestOutputWriterCSV.php =================================================================== --- php/phpruntests/trunk/src/testcase/output/rtTestOutputWriterCSV.php 2009-07-15 20:59:08 UTC (rev 284147) +++ php/phpruntests/trunk/src/testcase/output/rtTestOutputWriterCSV.php 2009-07-15 21:44:54 UTC (rev 284148) @@ -25,16 +25,21 @@ public function createOutput() { - foreach ($this->resultList as $testResult) { - $outputString = $testResult->getName(); - $testStatus = $testResult->getStatus(); - foreach($testStatus->getTestStateNames() as $name) { - if($testStatus->getValue($name)) { - $outputString .= " , ". strtoupper($name); - - } - } - $this->output .= $outputString."\n"; + foreach ($this->resultList as $testGroupResults) { + + foreach ($testGroupResults as $testResult) { + + $outputString = $testResult->getName(); + $testStatus = $testResult->getStatus(); + + foreach($testStatus->getTestStateNames() as $name) { + + if($testStatus->getValue($name)) { + $outputString .= " , ". strtoupper($name); + } + } + $this->output .= $outputString."\n"; + } } } Modified: php/phpruntests/trunk/src/testcase/output/rtTestOutputWriterList.php =================================================================== --- php/phpruntests/trunk/src/testcase/output/rtTestOutputWriterList.php 2009-07-15 20:59:08 UTC (rev 284147) +++ php/phpruntests/trunk/src/testcase/output/rtTestOutputWriterList.php 2009-07-15 21:44:54 UTC (rev 284148) @@ -24,20 +24,27 @@ public function createOutput() { - foreach ($this->resultList as $testResult) { - $outputString = ""; - $testStatus = $testResult->getStatus(); - foreach($testStatus->getTestStateNames() as $name) { - if($testStatus->getValue($name)) { - $outputString .= " ". strtoupper($name); - $outputString .= " " . $testStatus->getMessage($name); - } - } - $outputString .= " " . $testResult->getTitle(); - $outputString .= " [" . $testResult->getName() . ".phpt]"; - $this->output .= $outputString."\n"; + foreach ($this->resultList as $testGroupResults) { + + foreach ($testGroupResults as $testResult) { + + $outputString = ""; + $testStatus = $testResult->getStatus(); + + foreach($testStatus->getTestStateNames() as $name) { + + if ($testStatus->getValue($name)) { + $outputString .= " ". strtoupper($name); + $outputString .= " " . $testStatus->getMessage($name); + } + } + + $outputString .= " " . $testResult->getTitle(); + $outputString .= " [" . $testResult->getName() . ".phpt]"; + $this->output .= $outputString."\n"; + } } } } -?> +?> \ No newline at end of file Modified: php/phpruntests/trunk/src/testcase/output/rtTestOutputWriterXML.php =================================================================== --- php/phpruntests/trunk/src/testcase/output/rtTestOutputWriterXML.php 2009-07-15 20:59:08 UTC (rev 284147) +++ php/phpruntests/trunk/src/testcase/output/rtTestOutputWriterXML.php 2009-07-15 21:44:54 UTC (rev 284148) @@ -38,14 +38,97 @@ */ public function createOutput() { - foreach ($this->resultList as $result) { + $wdir = getcwd(); + + $global_state = array(); + $global_count = 0; + + foreach ($this->resultList as $testGroupResults) { + + // creat group-node + $groupNode = $this->dom->createElement('testgroup'); + $this->rootNode->appendChild($groupNode); - $test = $this->dom->createElement('testcase'); - $test->appendChild($this->dom->createElement('name', $result->getName())); - $test->appendChild($this->dom->createElement('status', $result->getStatus())); - $this->rootNode->appendChild($test); - } + $state = array(); + + foreach ($testGroupResults as $testResult) { + + // create test-node + $testNode = $this->dom->createElement('testcase'); + $groupNode->appendChild($testNode); + + // name + $n = explode($wdir, $testResult->getName()); + $n = explode('/', $n[1]); + $n = array_pop($n); + $testNode->setAttribute('name', $n); + + // status + $status = $testResult->getStatus(); + $s = $status->__toString(); + $testNode->setAttribute('status', strtoupper($s)); + + // title + $title = $testResult->getTitle(); + + if (strlen($title) > 0) { + $titleNode = $this->dom->createElement('title', utf8_encode(htmlentities($title))); + $testNode->appendChild($titleNode); + } + + // message + $msg = $status->getMessage($s); + + if (!is_null($msg)) { + $msgNode = $this->dom->createElement('message', utf8_encode(htmlentities($msg))); + $testNode->appendChild($msgNode); + } + + // files + $files = $testResult->getSavedFileNames(); + + if (sizeof($files) > 0) { + + $fileNode = $this->dom->createElement('files'); + $testNode->appendChild($fileNode); + + foreach ($files as $type => $file) { + $fileNode->setAttribute($type, $file); + } + } + + // count + if (!isset($state[$s])) { + $state[$s] = 0; + $global_state[$s] = 0; + } + + $state[$s]++; + $global_state[$s]++; + } + + $global_count += sizeof($testGroupResults); + + // add group-node attributes + + $n = explode($wdir, $testGroupResults[0]->getName()); + $n = explode('/', $n[1]); + array_pop($n); + $n = implode('/', $n); + + $groupNode->setAttribute('name', $n); + $groupNode->setAttribute('tests', sizeof($testGroupResults)); + + $time = round($testGroupResults[0]->getTime(), 2); + $groupNode->setAttribute('time', $time); + + foreach ($state as $k => $v) { + $groupNode->setAttribute($k, $v); + } + } + $this->dom->formatOutput = true; + $this->dom->normalizeDocument(); $this->output = $this->dom->saveXML(); } Modified: php/phpruntests/trunk/src/testcase/rtTestOutputWriter.php =================================================================== --- php/phpruntests/trunk/src/testcase/rtTestOutputWriter.php 2009-07-15 20:59:08 UTC (rev 284147) +++ php/phpruntests/trunk/src/testcase/rtTestOutputWriter.php 2009-07-15 21:44:54 UTC (rev 284148) @@ -2,8 +2,7 @@ /** * rtTestOutputWriter * - * Writes test output. This is concerned with status (PASS, FAIL etc) not - * with the log files. + * Writes test output. * * @category Testing * @package RUNTESTS @@ -20,10 +19,8 @@ protected $output = NULL; protected $type = 'list'; protected $overview = NULL; + - const OUTPUT_DIR = 'results'; - - public static function getInstance($type='list') { // defaults to 'list' - combatible with old version @@ -34,7 +31,7 @@ break; case 'html': - + return new rtTestOutputWriterHTML(); break; case 'csv': @@ -46,42 +43,43 @@ case 'txt': return new rtTestOutputWriterList(); break; - } } + - + /** + * + * @param array $resultList an array of arrays (testgroups) of rtTestResults + */ public function setResultList(array $resultList) { $this->resultList = $resultList; } - - - /** - * - */ + /** + * + * @return string $output + */ public function getOutput() { return $this->output; } - - - + + /** + * writes the the results to a file + * + * @param $filename + */ public function write($filename=null) { $this->createOutput(); if (!is_null($this->output)) { - - if (!file_exists(self::OUTPUT_DIR)) { - mkdir(self::OUTPUT_DIR); - } if (is_null($filename)) { - $filename = self::OUTPUT_DIR.'/results_'.round(microtime(true)).'.'.$this->type; + $filename = 'results_'.round(microtime(true)).'.'.$this->type; } if (file_put_contents($filename, $this->output)) { @@ -93,6 +91,13 @@ } + /** + * creates an overview about the test-results + * + * @param integer $groups + * @param integer $processCount + * @return string + */ public function getOverview($groups=NULL, $processCount=NULL) { // if the overview was already created retun it @@ -104,16 +109,19 @@ $state = array(); $count = 0; - foreach ($this->resultList as $result) { + foreach ($this->resultList as $testGroupResults) { + + foreach ($testGroupResults as $testResult) { - $s = $result->getStatus()->__toString(); - - if (!isset($state[$s])) { - $state[$s] = 0; - } - - $state[$s]++; - $count++; + $s = $testResult->getStatus()->__toString(); + + if (!isset($state[$s])) { + $state[$s] = 0; + } + + $state[$s]++; + $count++; + } } // create the output-string @@ -153,11 +161,11 @@ $str .= ' '; } - $str .= $v; + $str .= $v.' '; $p = round($v/$count*100,2); - $blanks = 5-strlen($v); + $blanks = 5-strlen($p); for ($b=0; $b<$blanks; $b++) { $str .= ' '; } @@ -180,7 +188,13 @@ } - + /** + * prints out the results of a testgroup + * + * @param array $results + * @param $state + * @param $cid + */ public static function flushResult(array $results, $state=0, $cid=NULL) { switch ($state) { @@ -189,7 +203,6 @@ return; break; - default: case 0: // a dot per test-case @@ -198,7 +211,6 @@ } break; - case 1: // every test-case incl. status print "\n"; foreach ($results as $result) { @@ -206,7 +218,6 @@ } break; - case 2: // details about not-passed tests foreach ($results as $result) { @@ -221,15 +232,19 @@ print strtoupper($name)."\t".$result->getName()."\n"; if ($name !== 'pass') { - print "desc:\t".$result->getTitle()."\n"; - print "msg:\t".$s->getMessage($name)."\n"; + print "DESC:\t".$result->getTitle()."\n"; + + $msg = $s->getMessage($name); + if (!is_null($msg)) { + print "MSG:\t".$msg."\n"; + } + print "\n"; } } break; - case 3: // all available details foreach ($results as $result) { @@ -239,31 +254,30 @@ print "\n"; print strtoupper($name)."\t".$result->getName()."\n"; - print "desc:\t".$result->getTitle()."\n"; - print "msg:\t".$s->getMessage($name)."\n"; + print "DESC:\t".$result->getTitle()."\n"; + + $msg = $s->getMessage($name); + if (!is_null($msg)) { + print "MSG:\t".$msg."\n"; + } + if (!is_null($cid)) { print "CID:\t$cid\n"; } + + print "MEM:\t".round(memory_get_usage()/1024, 2)." kB\n"; - print "mem:\t".round(memory_get_usage()/1024, 2)." kB\n"; - $files = $result->getSavedFileNames(); if (sizeof($files) > 0) { - print "files:\t"; - - foreach ($files as $file) { - print $file.', '; + print "FILES:\n"; + foreach ($files as $t => $file) { + print "$t:\t$file\n"; } - - print "\n"; } - - } - break; } @@ -272,4 +286,4 @@ } -?> +?> \ No newline at end of file Modified: php/phpruntests/trunk/src/testcase/rtTestResults.php =================================================================== --- php/phpruntests/trunk/src/testcase/rtTestResults.php 2009-07-15 20:59:08 UTC (rev 284147) +++ php/phpruntests/trunk/src/testcase/rtTestResults.php 2009-07-15 21:44:54 UTC (rev 284148) @@ -23,6 +23,7 @@ private $testName = ''; private $savedFileNames = array(); private $title = ''; + private $time = 0; public function __construct(rtPhpTest $testCase = null, rtTestStatus $testStatus = null) { @@ -166,5 +167,15 @@ { return $this->title; } + + public function getTime() + { + return $this->time; + } + + public function setTime($time) + { + $this->time = $time; + } } ?> Modified: php/phpruntests/trunk/src/testcase/rtTestStatus.php =================================================================== --- php/phpruntests/trunk/src/testcase/rtTestStatus.php 2009-07-15 20:59:08 UTC (rev 284147) +++ php/phpruntests/trunk/src/testcase/rtTestStatus.php 2009-07-15 21:44:54 UTC (rev 284148) @@ -39,7 +39,7 @@ { foreach ($this->testStateNames as $name) { $this->states[$name] = false; - $this->messages[$name] = '-- none --'; + $this->messages[$name] = null; } }