From 0f701cceeeaf391dc7133e9618dd8c989f712350 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 16 Aug 2006 06:56:37 +0000 Subject: [PATCH] Adding a unit test report class for SimpleTest --- UnitTestReport.php | 321 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 UnitTestReport.php diff --git a/UnitTestReport.php b/UnitTestReport.php new file mode 100644 index 0000000..b9f767f --- /dev/null +++ b/UnitTestReport.php @@ -0,0 +1,321 @@ + + + + + Unit Test Results + + + + + +

Unit Test Results: ' . $test . '

'; + } + + public function paintCaseStart($suite) + { + $this->suite = $case; + $this->block = ''; + $this->pass = 0; + $this->fail = 0; + $this->total = 0; + } + + public function paintMethodStart($method) + { + $this->method = $method; + $this->errors = array(); + $this->status = true; + } + + public function paintError($error) + { + $this->errors[] = $error; + } + + public function paintFail($message) + { + $this->status = false; + $this->errors[] = $message; + } + + public function paintPass($message) + { + } + + public function paintMethodEnd($method) + { + if ($this->status) + { + $this->pass++; + $this->_passes++; + } + else + { + $this->fail++; + $this->_fails++; + } + + $this->block .= "\n\t\t" . '
'; + $this->block .= "\n\t\t\t" . '
' . $method . '
'; + + if (sizeof($this->errors) > 0) + { + $this->block .= "\n\t\t\t" . '
'; + $this->block .= $this->formatInfo($this->errors); + $this->block .= "\n\t\t\t" . '
'; + } + + $this->block .= "\n\t\t" . '
'; + } + + private function formatInfo($list) + { + $output = ''; + $count = sizeof($list); + foreach ($list AS $err) + { + $i++; + $output .= "\n\t\t\t\t" . '
'; + $output .= "\n\t\t\t\t\t" . '
• ' . htmlspecialchars($err) . '
'; + $output .= "\n\t\t\t\t" . '
'; + } + + return $output; + } + + public function paintCaseEnd($case) + { + $total = $this->pass + $this->fail; + $successPercent = round(100 * (($total - $this->fail) / $total), 1); + + $this->html .= '
'; + $this->html .= "\n\t" . '
'; + $this->html .= "\n\t\t" . '' . $total . ' Tests, ' . $successPercent . '% Success' . ''; + $this->html .= "\n\t\t" . $case; + $this->html .= "\n\t" . '
'; + $this->html .= "\n\t" . '
'; + $this->html .= $this->block; + $this->html .= "\n\t" . '
'; + $this->html .= "\n" . '
'; + $this->html .= "\n\n" . '
' . "\n\n"; + } + + public function paintFooter($test) + { + $total = $this->getPassCount() + $this->getFailCount(); + echo ' +
+
The following is a report of how each unit test performed. If any errors or exceptions were thrown, they have been recorded below. Tests have been broken down into their test suite groups. Your overall statistics are here:
+ +
+ +
Total Tests: ' . $total . '
+
Number Success: ' . $this->getPassCount() . '
+
Number Fail: ' . $this->getFailCount() . '
+ +
+ +
Total Success Rate: ' . round(100 * ($this->getPassCount() / $total), 1) . '%
+
+ +
'; + + echo $this->html; + + echo ' + +'; + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.22.5