summaryrefslogtreecommitdiff
path: root/pear/tests/PEAR_ErrorStack/TestUnit.php
blob: 1fe703f664e5496e2cf0b4abb7e3420f1c582f06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

/**
 * TestUnit runs a TestSuite and returns a TestResult object.
 * And more than PHPUnit attach a listener to TestResult. 
 *
 * @version    $Id$
 * @author     Laurent Laville <pear@laurent-laville.org>
 * @package    HTML_CSS
 */

require_once 'PHPUnit.php';

class TestUnit extends PHPUnit {

    function &run(&$suite, $listener) {
        $result = new TestResult();
	$result->addListener($listener);
        $suite->run($result);

        return $result;
    }
}

class TestResult extends PHPUnit_TestResult {

    /* report result of test run */
    function report() {
	echo "</TABLE>";

	$nRun = $this->runCount();
	$nErrors = $this->errorCount();
	$nFailures = $this->failureCount();
	echo "<h2>Summary</h2>";

	printf("<p>%s test%s run.<br>", $nRun, ($nRun > 1) ? 's' : '');
	printf("%s error%s.<br>\n", $nErrors, ($nErrors > 1) ? 's' : '');
	printf("%s failure%s.<br>\n", $nFailures, ($nFailures > 1) ? 's' : '');
	if ($nFailures > 0) {
	    echo "<h2>Failure Details</h2>";
            print("<ol>\n");
            $failures = $this->failures();
            while (list($i, $failure) = each($failures)) {
                $failedTest = $failure->failedTest();
                printf("<li>%s\n", $failedTest->getName() );
                print("<ul>");
                printf("<li>%s\n", $failure->thrownException() );
                print("</ul>");
            }
            print("</ol>\n");
	}
    }

}
?>